AS3- ReferenceError:错误#1069:找不到属性

时间:2014-02-18 11:50:07

标签: actionscript-3 flash

有人可以告诉我为什么会收到此错误吗?

ReferenceError:错误#1069:在com.usmanzubairi.theAges.TheAges上找不到属性roll_mc,并且没有默认值。     在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);
    }
}

}

这是PirGame文档类代码:

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();
        }

    }

}

}

感谢。

1 个答案:

答案 0 :(得分:1)

如果您的roll_mc在PirGame符号中,并且我认为Pirgame类与该符号关联良好,请尝试修改您的PirGame类:

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();
            }
        }
    }
}

如果您只想点击roll_mc,请尝试以下操作:

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();
        }
    }
}

如果您不必重新显示runner_mc,可以将其从显示列表中删除,而不是让它不可见:

removeChild( runner_mc );