mercredi 15 février 2017

Defining Variables in Class File Causing Crashes

Currently, I'm still very new to classes in flash. I've been watching tons of videos about them and I am trying to learn more about Object Oriented Programming.

With that being said, I started defining variables and assigning them to symbols in my library, all in my class file. When I use these variables in my code, I get an error message popup which says the following

Error Message:

TypeError: Error #1009: Cannot access a property or method of a null object reference. at Movement()[C:\Users\Kevin\Main Directory\Flash\Clients\org\tcdsb\ZenithsReach\Movement.as:12] at game/frame1()[game::frame1:4] at runtime::ContentPlayer/loadInitialContent() at runtime::ContentPlayer/playRawContent() at runtime::ContentPlayer/playContent() at runtime::AppRunner/run() at ADLAppEntry/run() at global/runtime::ADLEntry()

My Movement.as class file:

package 
{
    import flash.display.MovieClip;
    import flash.events.TouchEvent;

    public class Movement extends MovieClip
    {
        function Movement()
        {
            trace("SUCCESS | Constructed Movement Class");
            down_dpad.addEventListener(TouchEvent.TOUCH_BEGIN, moveDownTouchBEGIN);
            down_dpad.addEventListener(TouchEvent.TOUCH_END, moveDownTouchEND);
            var inMotion:Boolean = false;

            var area1:Boolean = true;
            var area2:Boolean = false;
            var area3:Boolean = false;

            var player1:Boolean = true;
            var playerPosKeeper_mc:MovieClip = new mc_PlayerPosKeeper  ;
            addChild(playerPosKeeper_mc);
            playerPosKeeper_mc.x = 384;
            playerPosKeeper_mc.y = 46;

            var up_dpad:MovieClip = new dpad_Up  ;
            addChild(up_dpad);
            up_dpad.x = 55;
            up_dpad.y = 346;

            var down_dpad:MovieClip = new dpad_Down  ;
            addChild(down_dpad);
            down_dpad.x = 57;
            down_dpad.y = 442;

            var left_dpad:MovieClip = new dpad_Left  ;
            addChild(left_dpad);
            left_dpad.x = 19;
            left_dpad.y = 382;

            var right_dpad:MovieClip = new dpad_Right  ;
            addChild(right_dpad);
            right_dpad.x = 118;
            right_dpad.y = 382;

            var menu_dpad:MovieClip = new dpad_Menu  ;
            addChild(menu_dpad);
            menu_dpad.x = 61;
            menu_dpad.y = 386;

            var run_dpad:MovieClip = new dpad_Menu  ;
            addChild(run_dpad);
            run_dpad.x = 684;
            run_dpad.y = 386;

            var barrierRoof1_game:MovieClip = new game_BarrierRoof  ;
            addChild(barrierRoof1_game);
            barrierRoof1_game.x = 0;
            barrierRoof1_game.y = 0;

            var barrierRoof2_game:MovieClip = new game_BarrierRoof  ;
            addChild(barrierRoof2_game);
            barrierRoof2_game.x = 0;
            barrierRoof2_game.y = 470;

            var barrierSide1_game:MovieClip = new game_BarrierSide  ;
            addChild(barrierSide1_game);
            barrierSide1_game.x = 790;
            barrierSide1_game.y = 0;
            function moveDownTouchBEGIN(e:TouchEvent):void
            {
                if (player1 == true)
                {
                    if (area1 == true)
                    {
                        if (playerPosKeeper_mc.hitTestObject(barrierRoof1_game))
                        {

                        }
                    }
                    else
                    {
                        // add other areas in the future
                    }
                }
                else
                {
                    // if your not player1, then we need to find out what you are,
                    // and give you the proper walking animations
                }
            }

            function moveDownTouchEND(e:TouchEvent):void
            {

            }

        }

    }

}

Aucun commentaire:

Enregistrer un commentaire