我在GamePlay类中调用类函数时遇到问题

时间:2011-03-23 14:59:40

标签: flash actionscript-3

这是我的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(TimerEvent.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();
        }
    }
}

和我的班级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);
        }
    }
}

我收到此错误

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

这是否意味着我必须为GamePlay.as中的所有对象制作移动函数,我假设只要它们是公共的,我就可以在其他类中调用函数。

1 个答案:

答案 0 :(得分:0)

您的代码很好,我只是将2个类复制到一个新项目中,并且能够在每一帧都调用Player.Movement()。你还得到这个错误吗?