dimanche 19 février 2017

Why can't I access public variables from other classes?

I want to define my variables in my game document class, then use some of those variables in my Movement class. However, when I use these variables in my movement class I get tons of Compiling Errors saying that they're all undefined.

Thus my question is, why are my public variables not passed over to my other class? I have imported the class by doing import game; so this leaves me confussed. I'm probably just doing it wrong, but help is much appreciated.

Timeline

addChild((new Movement));

Game Document Class

package 
{
    import flash.display.MovieClip;
    import flash.utils.Timer;
    import flash.events.TimerEvent;

    public class game extends MovieClip
    {
        public var area1:Boolean = true;
        public var area2:Boolean = false;
        public var area3:Boolean = false;

        public var player1:Boolean = true;

        public var playerPosKeeper_mc:MovieClip = new mc_PlayerPosKeeper();

        public var up_dpad:MovieClip = new dpad_Up();
        public var down_dpad:MovieClip = new dpad_Down();
        public var left_dpad:MovieClip = new dpad_Left();
        public var right_dpad:MovieClip = new dpad_Right();
        public var menu_dpad:MovieClip = new dpad_Menu();
        public var run_dpad:MovieClip = new dpad_Menu();

        public var barrierRoof1_game:MovieClip = new game_BarrierRoof();
        public var barrierRoof2_game:MovieClip = new game_BarrierRoof();
        public var barrierSide1_game:MovieClip = new game_BarrierSide();
        public var barrierSide2_game:MovieClip = new game_BarrierSide();

        public function game()
        {
            trace("SUCCESS | Constructed Game Class");

        }
    }
}

Movement Class

package 
{
    import game;
    import flash.display.Stage;
    import flash.display.MovieClip;
    import flash.events.Event;
    import flash.events.TouchEvent;
    import flash.net.dns.AAAARecord;
    import flash.ui.Multitouch;
    import flash.ui.MultitouchInputMode;


    public class Movement extends MovieClip
    {
        var inMotion:Boolean = false;

        public function Movement()
        {
            trace("SUCCESS | Constructed Movement Class");

            addChild(playerPosKeeper_mc);
            playerPosKeeper_mc.x = 384;
            playerPosKeeper_mc.y = 46;

            addChild(up_dpad);
            up_dpad.x = 55;
            up_dpad.y = 336;

            addChild(down_dpad);
            down_dpad.x = 57;
            down_dpad.y = 432;

            addChild(left_dpad);
            left_dpad.x = 19;
            left_dpad.y = 372;

            addChild(right_dpad);
            right_dpad.x = 118;
            right_dpad.y = 372;

            addChild(menu_dpad);
            menu_dpad.x = 61;
            menu_dpad.y = 377;

            addChild(run_dpad);
            run_dpad.x = 684;
            run_dpad.y = 369;

            addChild(barrierRoof1_game);
            barrierRoof1_game.x = 0;
            barrierRoof1_game.y = 0;

            addChild(barrierRoof2_game);
            barrierRoof2_game.x = 0;
            barrierRoof2_game.y = 470;

            addChild(barrierSide1_game);
            barrierSide1_game.x = 0;
            barrierSide1_game.y = 0;

            addChild(barrierSide2_game);
            barrierSide2_game.x = 790;
            barrierSide2_game.y = 0;

            Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;

            up_dpad.addEventListener(TouchEvent.TOUCH_BEGIN, moveUpTouchBEGIN);
            up_dpad.addEventListener(TouchEvent.TOUCH_END, moveUpTouchEND);

        }
        public function moveUpTouchBEGIN(e:TouchEvent):void
        {
            trace("Touch Began")
        }

        public function moveUpTouchEND(e:TouchEvent):void
        {
            trace("Touch Ended")
        }
    }

}

Aucun commentaire:

Enregistrer un commentaire