Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
来自CustomClass的MovieClip上的AS3-gotoandstop()_Class_Actionscript 3_Flash_Movieclip_Animated - Fatal编程技术网

来自CustomClass的MovieClip上的AS3-gotoandstop()

来自CustomClass的MovieClip上的AS3-gotoandstop(),class,actionscript-3,flash,movieclip,animated,Class,Actionscript 3,Flash,Movieclip,Animated,不幸的是,我不是一个程序员,只是一个艺术家,但我必须做一个小游戏的例子,作为我的家庭作业的大学 因此,我为我的电影唇制作了一个名为Hero的类,并在Hero.as中制作了控制系统(来自教程)。它工作得很好,但是英雄正在旋转,因为我还没有设置它。这是英雄的一部分。例如: package AS { import flash.display.MovieClip; import flash.events.KeyboardEvent; import flash.events.Event; publi

不幸的是,我不是一个程序员,只是一个艺术家,但我必须做一个小游戏的例子,作为我的家庭作业的大学

因此,我为我的电影唇制作了一个名为Hero的类,并在Hero.as中制作了控制系统(来自教程)。它工作得很好,但是英雄正在旋转,因为我还没有设置它。这是英雄的一部分。例如:

package AS {

import flash.display.MovieClip;
import flash.events.KeyboardEvent;
import flash.events.Event;


public class Hero extends MovieClip {

    private var moveUp: Boolean;
    private var moveLeft: Boolean;
    private var moveDown: Boolean;
    private var moveRight: Boolean;
    private var moveSpeed: uint;

    public function Hero() {
        init();
    }

    protected function init() {
        moveUp = false;
        moveLeft = false;
        moveDown = false;
        moveRight = false;
        moveSpeed = 5;

        Constants.stageRef.addEventListener(KeyboardEvent.KEY_DOWN, keyPressedListener);
        Constants.stageRef.addEventListener(KeyboardEvent.KEY_UP, keyReleasedListener);
        Constants.stageRef.addEventListener(Event.ENTER_FRAME, frameListener);
    }

    //when you press down a key
    private function keyPressedListener(e: KeyboardEvent) {
        var key: uint = e.keyCode;
        if (key == 87 || key == 38) { //go to up with W or UP
            moveUp = true;
        } else if (key == 65 || key == 37) { //go to left with A or LEFT
            moveLeft = true;
        } else if (key == 83 || key == 40) { //go to down with S or DOWN
            moveDown = true;
        } else if (key == 68 || key == 39) { //go to right with D or RIGHT
            moveRight = true;
        }
    }

    //Blablabla
在游戏中。问题是我不知道如何在Hero.as中使用gotoAndStop()。首先,我必须停止英雄的旋转——gotoAndStop(“站前”)——然后我必须在每个部分(在按键侦听器中)设置英雄应该走的正确方向。 我就是这样认为的,使用错误的代码,可能在错误的地方:

        protected function init() {
        gotoAndStop("StandFront");   //------------Stop the character's spinning
        moveUp = false;
        moveLeft = false;
        moveDown = false;
        moveRight = false;
        moveSpeed = 5;

        //Blablabla...

    //when you press down a key
    private function keyPressedListener(e: KeyboardEvent) {
        var key: uint = e.keyCode;

        if (key == 87 || key == 38) { //go to up with W or UP
            moveUp = true;
            gotoAndStop("WalkFront"); //--------------- Play the animation where the
                                      //character's moving up while the player's
                                      //pressing the key W or UP.
        }
        //Blablablabla...
我不认为它是否有用,但在这里它是主要的。正如我作为一个类附加到Game.fla文档:

package AS {
    import flash.display.MovieClip;

    public class Main extends MovieClip {

        private var hero:Hero;


        public function Main() {
            init();
        }

        public function init(){
            Constants.stageRef=stage;

            hero=new Hero();
            hero.x=300;   //512;
            hero.y=300;   //418.9;
            stage.addChild(hero);
        }
    }
}
非常感谢你的帮助