开发者

I am having a problem calling a class function within my GamePlay class

Here is my GamePlay.as

package com.work.scripts
{
    import flash.display.Stage;
    import flash.events.Event;
    import flash.utils.Timer;
    import flash.events.TimerEvent;

    import com.work.scripts.player.Player;

    public class GamePlay
    {
        private var player:Player;
        private var stageRef:Stage;

        //timers
        private var gameDelay:Timer = new Timer(500, 1);

        public function GamePlay(stageRef:Stage)
        {
            this.stageRef = stageRef;

            //player variables
            player = new Player();

            player.x = 400;
            player.y = 500;
            //

            gameDelay.addEventListener(Timer开发者_开发技巧Event.TIMER_COMPLETE, StartGame, false, 0, true);
            gameDelay.start();
        }

        private function StartGame(e:TimerEvent):void
        {
            stageRef.addChild(player);

            stageRef.addEventListener(Event.ENTER_FRAME, MainGameLoop, false, 0, true);
        }

        private function MainGameLoop(e:Event):void
        {
            player.Movement();
        }
    }
}

and my class Player.as

package com.work.scripts.player
{
    import flash.display.MovieClip;
    import flash.events.Event;

    import scripts.utils.Bounds;

    public class Player extends MovieClip
    {
        private var bounds:Bounds = new Bounds();

        public function Player()
        {

        }

        public function Movement():void
        {
            startDrag(true, bounds.playArea);
        }
    }
}

I get this error

TypeError: Error #1006: Movement is not a function.
    at com.socialplay.scripts::GamePlay/MainGameLoop()

Does this mean I have to make movement functions for all my objects in GamePlay.as, I assumed I can just call functions in other classes as long as they are public.


Your code is fine, I just copied the 2 classes to a new project and was able to call Player.Movement() just fine every frame. Are you still getting this error?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜