A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: [RESOLVED] How do I change this code from AS2 to AS3?

  1. #1
    Junior Member
    Join Date
    Dec 2011
    Posts
    24

    resolved [RESOLVED] How do I change this code from AS2 to AS3?

    Hi there, I'm using a tutorial to create a game, however it uses AS2 and I am using AS3. As a result the coding below brings up errors 1086 and 1084 (Syntax error: expecting semicolon before leftbrace and Syntax error: expecting rightbrace before leftbrace respectively) in Line 4. Can anyone help me convert this code to AS3 please?
    Here's the code:
    Actionscript Code:
    var walkSpeed:Number = 16;
    mcMain.addEventListener
    {
        onClipEvent(load){
            walkSpeed = 16;
        }
        onClipEvent(enterFrame){
            if(Key.isDown(Key.UP)){
                _y-= walkSpeed
            }
        }
    }
    Last edited by JimbobD; 02-17-2012 at 04:48 PM. Reason: Just changed title of post to match new request.

  2. #2
    Senior Member
    Join Date
    May 2010
    Posts
    178
    Learn AS3 before attempting to AS2 Game Structure.

    You have to know some of the fundamentals of AS3 first.

    Also visit www.adobe.com to see the AS2 to AS3 migration section.



    poltuda

  3. #3
    Junior Member
    Join Date
    Dec 2011
    Posts
    24

    How to stop a function?

    Thanks for the reply, I learnt a little and changed it to this:

    Actionscript Code:
    var upKeyDown:Boolean = false;
    var walkSpeed:Number = 16;

    mcMain.addEventListener(Event.ENTER_FRAME, moveChar);
    function moveChar(event:Event):void{
        if(upKeyDown){
            mcMain.y -= walkSpeed;
            return;
        }
    }

    mcUpKey.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);
    function fl_MouseClickHandler(event:MouseEvent):void
    {
        upKeyDown = true;
    }
    However, when upKeyDown becomes true, my main character doesn't stop moving. Is there a way other than using return; to make him move once only?

  4. #4
    Senior Member
    Join Date
    May 2010
    Posts
    178
    MouseEvent.MOUSE_DOWN

    MouseEvent.MOUSE_UP

    No need of MouseEvent.CLICK then....



    Good going



    poltuda

  5. #5
    Junior Member
    Join Date
    Dec 2011
    Posts
    24
    Thank you for the reply, that's solved it

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center