1
votes

Can someone tell me why I get this error?

ReferenceError: Error #1069: Property roll_mc not found on com.usmanzubairi.theAges.TheAges and there is no default value. at com.usmanzubairi.theAges::PirGame/rolling()

package com.usmanzubairi.theAges
{  
    import flash.display.MovieClip;
    import flash.events.*;
    import flash.media.*;

public class TheAges extends MovieClip
{
    private var game:PirGame;
    private var game2:PreGame;
    private var game3:SupGame;


    public function TheAges()
    {
        stage.addEventListener(MouseEvent.CLICK, startGame);
    }


    private function startGame(event:Event):void
    {
        if (event.target != player_btn)
        {
                removeEventListener(MouseEvent.CLICK, startGame);

                game = new PirGame();
                addChild(game);
        }

        else
        {
                addChild(player_mc);
                player_mc.visible = true;
                player_mc.play();
        }

                    if (event.target == player_mc.tom_mc)
                    {
                        removeEventListener(MouseEvent.CLICK, startGame);

                        game2 = new PreGame();
                        addChild(game2);
                    }

                    if (event.target == player_mc.pete_mc)
                    {
                        removeEventListener(MouseEvent.CLICK, startGame);

                        game = new PirGame();
                        addChild(game);
                    }

                    if(event.target == player_mc.sam_mc)
                    {
                        removeEventListener(MouseEvent.CLICK, startGame);

                        game3 = new SupGame();
                        addChild(game3);
                    }

    }   

    public function gameOver():void
    {
        removeChild(game);
        game = null;
        stage.addEventListener(MouseEvent.CLICK, startGame);
    }
}

}

Here's the PirGame document class code:

package com.usmanzubairi.theAges
{
    import flash.utils.Timer;
    import flash.events.*;
    import flash.display.*;
    import flash.geom.Matrix;
    import flash.net.SharedObject;

public class PirGame extends MovieClip
{
    public function PirGame() 
    {
        addEventListener(MouseEvent.CLICK,rolling);
    }

    private function rolling (event:Event):void
    {
        if (event.target == MovieClip(root).roll_mc)
        {
            addChild(roll)
            roll.visible = true;
            runner_mc.visible = false;
            roll.play();
        }

    }

}

}

Thanks.

1
Are you going to say something about "roll" stuff? also what is roll_mc you've used in rolling() function... - Bora Kasap
"roll" is a rolling animation and "roll_mc" is the button that plays that rolling animation. - user3302134
are you sure roll_mc exists ? try test it before your condition to see the value (if( MovieClip(root).roll_mc && event.target == MovieClip(root).roll_mc )). If null, the object don't exists. Try debug your movie (ctrl+maj+enter) instead of running it (ctrl+enter), you will have better informations on the error and you could see all variables values a the error time. - Benjamin BOUFFIER
@Binou, thanks. I had to define the movie clip in the class. So I added public var roll_mc:MovieClip;, after that I didn't get the error. However when I click the button the rolling animation doesn't play, it gets stuck and continues with the running animation. Any ideas? Thanks. - user3302134
do you have a button named roll_mc on your stage in flash pro ? is it on the main stage or in an other symbol ? if your roll_mc is on your PirGame symbol you cannnot access it with MovieClip(root).roll_mc, if it is realy placed on the main stage you don't have to declare it with public var roll_mc:MovieClip; - Benjamin BOUFFIER

1 Answers

2
votes

If your roll_mc is in your PirGame symbol, and i think Pirgame class is well associated with the symbol, try modify your PirGame class a s follow:

package com.usmanzubairi.theAges
{
    import flash.utils.Timer;
    import flash.events.*;
    import flash.display.*;
    import flash.geom.Matrix;
    import flash.net.SharedObject;

    public class PirGame extends MovieClip
    {
        public function PirGame() 
        {
            addEventListener(MouseEvent.CLICK,rolling);
        }

        private function rolling (event:Event):void
        {
            trace( event.target, roll_mc );
            // change MovieClip(root).roll_mc to this.roll_mc as roll_mc is on this symbol and not on the root.
            if( event.target == this.roll_mc )
            {
                trace( 'roll_mc clicked' );
                addChild( roll )
                roll.visible = true;
                runner_mc.visible = false;
                roll.play();
            }
        }
    }
}

if you just want the roll_mc be clickable try the following:

package com.usmanzubairi.theAges
{
    import flash.utils.Timer;
    import flash.events.*;
    import flash.display.*;
    import flash.geom.Matrix;
    import flash.net.SharedObject;

    public class PirGame extends MovieClip
    {
        public function PirGame() 
        {
            if( roll_mc )   roll_mc.addEventListener( MouseEvent.CLICK, rolling );
            else            addEventListener( Event.ADDED_TO_STAGE, _onStage );
        }

        private function _onStage( e:Event ):void
        {
            removeEventListener( Event.ADDED_TO_STAGE, _onStage );
            roll_mc.addEventListener( MouseEvent.CLICK, rolling );
        }

        private function rolling( e:Event ):void
        {
            trace( 'roll_mc clicked' );
            addChild( roll )
            roll.visible = true;
            runner_mc.visible = false;
            roll.play();
        }
    }
}

if you don't have to re display the runner_mc you can remove it from the display list instead of make it not visible:

removeChild( runner_mc );