AS3 在特定画面上移动物体

AS3 MOVING OBJECT ON SPECIFIC FRAME

所以我已经在这个游戏上工作了一个星期了,我根本没有任何编码背景,所以我试图在这里和那里找到教程..然后我想出了这个问题...

所以我想做的是当我点击内部第 80 帧时将对象 (CHARA) 移动到右侧(CHARA,这是一个具有 99 帧的嵌套影片剪辑)然后当我点击帧时将其移回原始位置99... 问题是我所做的任何事情都不能使我的对象移动(顺便说一句,movieClip 仍在播放)我做错了什么?我只是把代码放在了错误的位置吗?? (仅当我将代码 x= 直接放在第 80 帧内时,CHAR 才会移动,但我尝试在此处使用 class)

这是我的代码,抱歉,我知道它很乱,这是我的第一个代码,我在这里尽力而为

package {

    public class Main extends MovieClip {

        public var CHARA:CHAR = new CHAR;//my main char
        public var rasen:Rasen_button = new Rasen_button;//the skill button
        public var NPCS:NPC = new NPC;// the npc

        public function Main() {
            var ally:Array = [265,296];//where me and my ally should be
            var jutsu:Array = [330,180];// where the buttons should be
            var enemy:Array = [450,294];//where the enemies should be

            addChild(NPCS);
            NPCS.x = enemy[0];
            NPCS.y = enemy[1];
            NPCS.scaleX *=  -1;

            addChild(rasen);
            rasen.x = jutsu[1];
            rasen.y = jutsu[0];

            addChild(CHARA);
            CHARA.x = ally[0];
            CHARA.y = ally[1];
            rasen.addEventListener(MouseEvent.CLICK, f2_MouseOverHandler);
            function f2_MouseOverHandler(event:MouseEvent):void {
                CHARA.gotoAndPlay(46); //here is the problem
                if (CHARA.frame == 80)
                {
                    CHARA.x = ally[1]; //just random possition for now
                }

            }
        }
    }
}

有什么建议吗?

您的 if 语句位于点击处理程序 (f2_MouseOverHandler) 中,因此它仅在用户点击 rasen 时执行,不一定在播放到达帧 [=14] 时执行=].这是与时序和代码执行相关的初学者常见错误。最直接的解决方案是编写一些代码,使用 ENTER_FRAME 处理程序在每一帧执行:

        rasen.addEventListener(MouseEvent.CLICK, f2_MouseOverHandler);
        function f2_MouseOverHandler(event:MouseEvent):void {
            CHARA.gotoAndPlay(46); //here is the problem

            // add an ENTER_FRAME handler to check every frame
            CHARA.addEventListener(Event.ENTER_FRAME, chara_EnterFrameHandler)
        }
        function chara_EnterFrameHandler(event:Event):void {
            if (CHARA.currentFrame == 80)
            {
                CHARA.x = ally[1]; //just random possition for now

                // remove the ENTER_FRAME after the condition is met
                // so it stops executing each frame
                CHARA.removeEventListener(Event.ENTER_FRAME, chara_EnterFrameHandler);
            }
        }