0

我对这整个 as3 的事情是新手,我非常挣扎。在过去的两天里,我一直坐着,试图做一些我可以想象的事情,以便让其他阅读本文的人变得简单。我正在尝试创建一个游戏,其中我有一个由键盘键控制的滑板。但是,当我输入此代码时,我收到 1084 错误,请在我将笔记本电脑扔出窗外之前提供帮助。谢谢!!

package {
    import flash.display.*;
    import flash.events.*;enter code here

    public class skatefate extends MovieClip {

            var the_skater:Sprite = new Sprite();
            the_skater.addChild:(skater);



            var moveLeft:Boolean = false;
            var moveRight:Boolean = false;
            var moveUp:Boolean = false;
            var moveDown:Boolean = false;

            stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressedDown);
            stage.addEventListener(KeyboardEvent.KEY_UP, keyPressedUp);
            stage.addEventListener(Event.ENTER_FRAME, moveskater);

            function keyPressedDown(event:KeyboardEvent) {
                if (event.keyCode == 37) {
                moveLeft = true;
            } else if (event.keyCode == 39) {
                moveRight = true;
            } else if (event.keyCode == 65) {
                moveUp = true;
            } else if (event.keyCode == 90) {
                moveDown = true;
    }
}


            function keyPressedUp(event:KeyboardEvent) {
                if (event.keyCode == 37) {
                moveLeft = false;
            } else if (event.keyCode == 39) {
                moveRight = false;
            } else if (event.keyCode == 65) {
                moveUp = false;
            } else if (event.keyCode == 90) {
                moveDown = false;
    }
}


            function moveskater(event:Event) {
            var speed:uint = 20;

            if (moveLeft) {
            skater.x -= speed;
            if (skater.x < 0){
        skater.x = 800;
        }
    }
            }
    if (moveRight) {
        skater.x += speed;
        if (skater.x > 800){
        skater.x = 0;
        }
    }
    if (moveUp) {
        skater.y -= speed;
        if (skater.y > 0){
        skater.y = 0;               
    }
    }
    if (moveDown) {
        skater.y += speed;
        if (skater.y > 0){
            skater.y = 0;


            }
    }
4

1 回答 1

0

我尝试了您的代码,但没有收到您的错误。您的示例会引发其他错误和问题。所以我的建议是这两件事..

  1. 正确构建代码...

    package  
    {
    
    //IMPORTS go here
    
    //Declare your Class
    public class skatefate extends MovieClip 
    {
        //VARS go here 
        //*******************************************************************
        //note: later you may also add other VARS inside functions as needed 
        //(but were not originally put (declared) in this section)
        //*******************************************************************
    
        //Declare main function of your Class (must have same name as Class (.as)
        public function skatefate() 
        {
            //Constructor code here
            //************************************************************************
            // Your main program code and related functions (K/board etc) go here and 
            // will reference your VARS declared above in public Class construction)
            //************************************************************************
    
        } //End of (public) Function
    
    } //End of (public) Class 
    
    } //End of Package
    
  2. 万一你仍然挣扎,你的代码的这个编辑应该编译。从那里你可以学习和学习。希望在这个残酷的世界中,还有一台笔记本电脑能够生存下来。

    package 
    {
        import flash.display.*;
        import flash.events.*; //enter code here
    
    //Declare your Class
    public class skatefate extends MovieClip {
    
    var the_skater:Sprite = new Sprite();
    var skater:Sprite = new Sprite(); //hide line if skater exists already (i.e in  Library)
    var speed:uint = 20;
    
    //Declare main function of your Class
    public function skatefate () 
    {
        var moveLeft:Boolean = false;
        var moveRight:Boolean = false;
        var moveUp:Boolean = false;
        var moveDown:Boolean = false;
    
        stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressedDown);
        stage.addEventListener(KeyboardEvent.KEY_UP, keyPressedUp);
        stage.addEventListener(Event.ENTER_FRAME, moveskater);
    
    
        the_skater.addChild(skater);
        addChild(the_skater); //adds to stage
    
        function keyPressedDown (event:KeyboardEvent) 
        {
            if (event.keyCode == 37)        { moveLeft = true; } 
            else if (event.keyCode == 39)   { moveRight = true; }
            else if (event.keyCode == 65)   { moveUp = true; } 
            else if (event.keyCode == 90)   { moveDown = true; }
        }
    
        function keyPressedUp (event:KeyboardEvent) 
        {
            if (event.keyCode == 37)        { moveLeft = false; } 
            else if (event.keyCode == 39)   { moveRight = false; }
            else if (event.keyCode == 65)   { moveUp = false; } 
            else if (event.keyCode == 90)   { moveDown = false; }
        }
    
        function moveskater(event:Event) 
        {
            //var speed:uint = 20; //already declared at top
            //speed = 20; // later change 'speed' this way by updating number
    
            if (moveLeft)   {
                                skater.x -= speed;
                                if (skater.x < 0)
                                { skater.x = 800; }
                            }
    
            if (moveRight)  {
                                skater.x += speed;
                                if (skater.x > 800)
                                { skater.x = 0; }
                            }
    
            if (moveUp)     {
                                skater.y -= speed;
                                if (skater.y > 0)
                                { skater.y = 0; }
                            }
    
            if (moveDown)   {   skater.y += speed;
                                if (skater.y > 0)
                                { skater.y = 0; }
                            }
        } //close 'moveskater' function
    
    
    } //End of your (public) Function
    
    } //End of your (public) Class 
    
    } //End of Package
    

希望能帮助到你。在评论中寻求建议,如果对您有用,请不要忘记勾选“正确答案”。这就是我们在 Stack Overflow 上说“谢谢”的方式。

于 2013-11-06T21:39:54.307 回答