# AS2 MovieClip character keyboard control

**URL:** <https://forum.kirupa.com/t/as2-movieclip-character-keyboard-control/634204>\
**Category:** flash\
**Created:** [February 2, 2016, 2:09pm UTC](https://forum.kirupa.com/t/as2-movieclip-character-keyboard-control/634204 "2016-02-02T14:09:18Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Olav\_Ata](https://avatars.discourse-cdn.com/v4/letter/o/2acd7d/32.png) [@Olav\_Ata](https://forum.kirupa.com/u/Olav_Ata)\
**Post date:** [February 2, 2016, 2:09pm UTC](https://forum.kirupa.com/t/as2-movieclip-character-keyboard-control/634204/1 "2016-02-02T14:09:18Z")

</div>

Hi guys,

I google it and i found similar but not exactly the same issue resolver.  
That’s way i’m posting here.  
So , Here is scenario:

On the Main time line i have one only keyframe. I the Scene i have only one MovieClip with instance name “currentPlayer\_mc”. It is empty initially (or just simple circle not the necessary image).  
In the Library I have two other MovieClips:

1. girlFront\_mc - contains static position person image
2. girlWalking\_mc - contains a series of keyframes - animated walk (it’s simple).

and finaly i have one container MovieClip that holds those two MovieClips mentioned above (simple again).  
This container MovieClips has exported in AcstionScript with Identifier “girlWalk\_mc”.

 ![](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/2X/4/4e13a00196eecbada9923066744367c044f57ca7.png)  
The action layer contains two stop(); at each two keyframes. I labeled this two keyframes as in the image above shown.

The problem!  
With the code below i attach the container MovieClip “girlWalk\_mc” to the currentPlayer\_mc.  
When I press the Left arrow key the currentPlayer\_mc (with properly attached container girlWalk\_mc) moves LEFT.  
When I press the Right arrow key the currentPlayer\_mc moves RIGHT.  
But it doesn’t plays the current MovieClip inside of It e.g. When it is movement (no matter left or right) to play the nested girlWalking\_mc. It shows just image of the first keyframe of girlWalking\_mc. (its just stops there).

Here is the code:

\_global.characterSpeed = 10;  
\_global.player = “girlwalking\_mc”;  
\_global.initCharacterY:Number;

currentPlayer\_mc.attachMovie( \_global.player, “crntPlayer\_mc”, this.getNextHighestDepth());

\_global.initCharacterY = currentPlayer\_mc.\_y;

currentPlayer\_mc.onEnterFrame = function():Void{  
this.crntPlayer\_mc.gotoAndStop(“stopWalk”);  
if(Key.isDown(Key.LEFT)){  
this.crntPlayer\_mc.gotoAndStop(“goWalk”);  
this.\_x -= \_global.characterSpeed;  
this.\_xscale = 100;  
}  
if(Key.isDown(Key.RIGHT)){  
this.crntPlayer\_mc.gotoAndStop(“goWalk”);  
this.\_x += \_global.characterSpeed;  
this.\_xscale = -100;  
}  
};
