dcsimg
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: as2 to as3 Migration help...easy question!

  1. #1
    Junior Member
    Join Date
    Mar 2009
    Posts
    12

    as2 to as3 Migration help...easy question!

    Hey guys, first of I would like to apologize if this question has been already answered

    I need help translating this follow AS2 code:
    PHP Code:
    onClipEvent(enterFrame){
       if(
    Key.isDown(Key.LEFT)){
          
    _x -= 5;
       }else if(
    Key.isDown(Key.RIGHT)){
          
    _x += 5;

    I've been having a lot of trouble understanding AS3 and I would be eternally grateful for help
    Thanks!

  2. #2
    ___________________
    Join Date
    May 2004
    Posts
    3,174
    i wouldn't use enter frame, you can use a key listener
    PHP Code:
    // replace "target" with the clip you want to move
    function keyHandler(event:KeyboardEvent):void{
      switch(
    event.keyCode){
        case 
    37 :
          
    target.-= 5;
          break;
        case 
    39 :
         
    target.+= 5;
         break;
      }
    }
    stage.addEventListener("keyDown"keyHandler); 

  3. #3
    Senior Member
    Join Date
    May 2009
    Posts
    280
    Quote Originally Posted by moagrius View Post
    i wouldn't use enter frame, you can use a key listener
    PHP Code:
    // replace "target" with the clip you want to move
    function keyHandler(event:KeyboardEvent):void{
      switch(
    event.keyCode){
        case 
    37 :
          
    target.-= 5;
          break;
        case 
    39 :
         
    target.+= 5;
         break;
      }
    }
    stage.addEventListener("keyDown"keyHandler); 
    why not stage.addEventListener(KeyboardEvent.KEY_DOWN, keyHandler);?

  4. #4
    ___________________
    Join Date
    May 2004
    Posts
    3,174
    it's the same thing. the only difference is that you'll get a compiler warning if you have a typo in a constant, but won't if you just use the string literal, but i just prefer typing the string directly. call it habit. and technically, it's a little more efficient (i know the it wouldn't be noticeable, but some "best practices" are equally silly).

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