# Actionscript 2 to 3. please help!

**URL:** <https://forum.kirupa.com/t/actionscript-2-to-3-please-help/260374>\
**Category:** Uncategorized\
**Created:** [May 14, 2008, 10:06pm UTC](https://forum.kirupa.com/t/actionscript-2-to-3-please-help/260374 "2008-05-14T22:06:59Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![highway81](https://avatars.discourse-cdn.com/v4/letter/h/8dc957/32.png) [@highway81](https://forum.kirupa.com/u/highway81)\
**Post date:** [May 14, 2008, 10:06pm UTC](https://forum.kirupa.com/t/actionscript-2-to-3-please-help/260374/1 "2008-05-14T22:06:59Z")

</div>

hey,

i have just started studying actionscript 3 at college and need some help migrating some script from 2 to 3. any help would be greatly appreciated:

ryu\_mc.step=15;  
ryu\_mc.attack = false;  
ryu\_mc.stance= 1;  
ryu\_mc.crouch=false;

this.onEnterFrame = function()  
{  
if(ryu\_mc.attack==false)  
{  
if (Key.isDown (Key.RIGHT) )  
{  
ryu\_mc.\_xscale = 100;  
ryu\_mc.stance=1;  
ryu\_mc.\_x+=ryu\_mc.step;  
ryu\_mc.gotoAndStop(“walking”);  
}  
else if (Key.isDown (Key.LEFT) )  
{  
ryu\_mc.\_xscale = -100;  
ryu\_mc.stance=0;  
ryu\_mc.\_x-=ryu\_mc.step;  
ryu\_mc.gotoAndStop(“walking”);  
}  
}  
}

it is simply script in AS2 to make a character move left and right on the key getting pressed. any help migrating this to AS3 would be appreciated.

thanks

---

<div class="post-metadata">

**Author:** ![RebuiltJorge](https://avatars.discourse-cdn.com/v4/letter/r/94ad74/32.png) [@RebuiltJorge](https://forum.kirupa.com/u/RebuiltJorge)\
**Post date:** [May 14, 2008, 11:15pm UTC](https://forum.kirupa.com/t/actionscript-2-to-3-please-help/260374/2 "2008-05-14T23:15:58Z")

</div>

Here try this, it worked for me

```
ActionScript Code:
[LEFT][COLOR=#808080]*//initialize your variables, false by default*[/COLOR]

```

[COLOR=#000000] **var** [/COLOR] keyLeft:[COLOR=#0000FF]Boolean[/COLOR];  
[COLOR=#000000] **var** [/COLOR] keyRight:[COLOR=#0000FF]Boolean[/COLOR];

[COLOR=#808080]_//add keyboard event listeners to the stage that ‘listen’ for keyboard key presses_[/COLOR]  
[COLOR=#0000FF]stage[/COLOR].[COLOR=#000080]addEventListener[/COLOR]COLOR=#000000[/COLOR];  
[COLOR=#0000FF]stage[/COLOR].[COLOR=#000080]addEventListener[/COLOR]COLOR=#000000[/COLOR];

[COLOR=#808080]_//give you motion whenever keyLeft or keyRight is set to true;_[/COLOR]  
addEventListenerCOLOR=#000000[/COLOR];

[COLOR=#808080]_//when key is pressed down_[/COLOR]  
[COLOR=#000000] **function** [/COLOR] keyDownFunctionCOLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]  
[COLOR=#808080]_//keyCode 37 is the left arrow key, 38 is up arrow, 39 is right arrow, 40 is down, and 32 is the spacebar_[/COLOR]  
[COLOR=#0000FF]if[/COLOR] [COLOR=#000000]([/COLOR]evt.[COLOR=#000080]keyCode[/COLOR] == [COLOR=#000080]37[/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]  
keyLeft = [COLOR=#000000] **true** [/COLOR];  
[COLOR=#000000]}[/COLOR]  
[COLOR=#0000FF]if[/COLOR] [COLOR=#000000]([/COLOR]evt.[COLOR=#000080]keyCode[/COLOR] == [COLOR=#000080]39[/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]  
keyRight = [COLOR=#000000] **true** [/COLOR];

```
[COLOR=#000000]}[/COLOR]

```

[COLOR=#000000]}[/COLOR]

[COLOR=#000000] **function** [/COLOR] keyUpFunctionCOLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]  
[COLOR=#808080]_//whenever a key is lifted, the variable is set to false, and the character stops moving_[/COLOR]  
[COLOR=#0000FF]if[/COLOR] [COLOR=#000000]([/COLOR]evt.[COLOR=#000080]keyCode[/COLOR] == [COLOR=#000080]37[/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]  
keyLeft = [COLOR=#000000] **false** [/COLOR];  
[COLOR=#000000]}[/COLOR]  
[COLOR=#0000FF]if[/COLOR] [COLOR=#000000]([/COLOR]evt.[COLOR=#000080]keyCode[/COLOR] == [COLOR=#000080]39[/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]  
keyRight = [COLOR=#000000] **false** [/COLOR];

```
[COLOR=#000000]}[/COLOR]

```

[COLOR=#000000]}[/COLOR]

[COLOR=#808080]_//comes into play whenver keyLeft or keyRight is set to true_[/COLOR]  
[COLOR=#000000] **function** [/COLOR] moveObjectCOLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]  
[COLOR=#0000FF]if[/COLOR] COLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]

```
    ryu_mc.[COLOR=#000080]scaleX[/COLOR] = -[COLOR=#000080]100[/COLOR];
    ryu_mc.[COLOR=#000080]stance[/COLOR]=[COLOR=#000080]0[/COLOR];
    ryu_mc.[COLOR=#000080]x[/COLOR]-=ryu_mc.[COLOR=#000080]step[/COLOR];
    ryu_mc.[COLOR=#0000FF]gotoAndStop[/COLOR][COLOR=#000000]([/COLOR][COLOR=#FF0000]"walking"[/COLOR][COLOR=#000000])[/COLOR];

[COLOR=#000000]}[/COLOR] [COLOR=#0000FF]else[/COLOR] [COLOR=#0000FF]if[/COLOR] [COLOR=#000000]([/COLOR]keyRight[COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]

    ryu_mc.[COLOR=#000080]scaleX[/COLOR] = [COLOR=#000080]100[/COLOR];
    ryu_mc.[COLOR=#000080]stance[/COLOR]=[COLOR=#000080]1[/COLOR];
    ryu_mc.[COLOR=#000080]x[/COLOR]+=ryu_mc.[COLOR=#000080]step[/COLOR];
    ryu_mc.[COLOR=#0000FF]gotoAndStop[/COLOR][COLOR=#000000]([/COLOR][COLOR=#FF0000]"walking"[/COLOR][COLOR=#000000])[/COLOR];

[COLOR=#000000]}[/COLOR]

```

[COLOR=#000000]}[/COLOR]  
[/LEFT]

---

<div class="post-metadata">

**Author:** ![ajcates](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/ajcates/32/2435_2.png) [@ajcates](https://forum.kirupa.com/u/ajcates)\
**Post date:** [May 14, 2008, 11:55pm UTC](https://forum.kirupa.com/t/actionscript-2-to-3-please-help/260374/3 "2008-05-14T23:55:49Z")

</div>

If you want to use keyDown in as3 you should check out this class. [http://www.senocular.com/flash/actionscript.php?file=ActionScript\_3.0/com/senocular/utils/KeyObject.as](http://www.senocular.com/flash/actionscript.php?file=ActionScript_3.0/com/senocular/utils/KeyObject.as)

---

<div class="post-metadata">

**Author:** ![rakesh\_pal](https://avatars.discourse-cdn.com/v4/letter/r/50afbb/32.png) [@rakesh\_pal](https://forum.kirupa.com/u/rakesh_pal)\
**Post date:** [May 15, 2008, 6:10am UTC](https://forum.kirupa.com/t/actionscript-2-to-3-please-help/260374/4 "2008-05-15T06:10:31Z")

</div>

I want learn flash action action script from started.  
can teach me ?  
but i dont know english  
please give me the tutorial with hindhi text

---

<div class="post-metadata">

**Author:** ![rakesh\_pal](https://avatars.discourse-cdn.com/v4/letter/r/50afbb/32.png) [@rakesh\_pal](https://forum.kirupa.com/u/rakesh_pal)\
**Post date:** [May 15, 2008, 6:11am UTC](https://forum.kirupa.com/t/actionscript-2-to-3-please-help/260374/5 "2008-05-15T06:11:12Z")

</div>

please give me the tutorial

---

<div class="post-metadata">

**Author:** ![ajcates](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/ajcates/32/2435_2.png) [@ajcates](https://forum.kirupa.com/u/ajcates)\
**Post date:** [May 15, 2008, 6:50am UTC](https://forum.kirupa.com/t/actionscript-2-to-3-please-help/260374/6 "2008-05-15T06:50:02Z")

</div>

My advice would be searching Google, for action script tutorials in your native language. Also maybe learning more English would help you, as there are lots of tutorials in English.

---

<div class="post-metadata">

**Author:** ![highway81](https://avatars.discourse-cdn.com/v4/letter/h/8dc957/32.png) [@highway81](https://forum.kirupa.com/u/highway81)\
**Post date:** [May 15, 2008, 8:44am UTC](https://forum.kirupa.com/t/actionscript-2-to-3-please-help/260374/7 "2008-05-15T08:44:08Z")

</div>

thank you to everyone for your responses. they are very much appreciated.
