AS3错误1084语法错误期望在dot之前的rightparen

时间:2013-11-06 16:39:21

标签: actionscript-3 flash runtime-error flash-cs3

我是这个整体的新手,我正在努力奋斗。过去两天我一直坐着试着做一些我可以成像的东西,对其他人来说都很简单。我正在尝试创建一个游戏,我有一个由键盘键控制的滑板边。但是,当我输入此代码时,我得到一个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;


            }
    }

1 个答案:

答案 0 :(得分: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. 只是让你仍然挣扎,所显示的代码编辑应该编译。从那里你可以学习&amp;学习。希望再有一台笔记本电脑能够在这个残酷的世界中存活下来。

    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
    
  3. 希望它有所帮助。在评论中征求意见,如果适合您,请不要忘记勾选“正确答案”。这就是我们在Stack Overflow上说“谢谢”的方式。