February 2010
M T W T F S S
« Jan   Mar »
1234567
891011121314
15161718192021
22232425262728

Moving movie clip in the container

Problem
Need movie movie clip in the container using keyboard arrows.

Solution
Using event.keyCode for moving our movie clip. And coordinates of the container and movie clip what need to move for control moving.

Detailed explanation

index9


stage.addEventListener(KeyboardEvent.KEY_DOWN, starMoving);

function starMoving(event:KeyboardEvent):void {

trace(event.keyCode);

switch (event.keyCode) {

case Keyboard.UP :

face_mc.y-=10;

if (face_mc.y

face_mc.y=container_mc.y;

}

break;

case Keyboard.DOWN :

face_mc.y+=10;

if
(face_mc.y+face_mc.height>container_mc.y+container_mc.height) {

face_mc.y=container_mc.y+container_mc.height-face_mc.height;

}

break;

case Keyboard.LEFT :

face_mc.x-=10;

if (face_mc.x

face_mc.x=container_mc.x;

}

break;

case Keyboard.RIGHT :

face_mc.x+=10;

if
(face_mc.x+face_mc.width>container_mc.x+container_mc.width) {

face_mc.x=container_mc.x+container_mc.width-face_mc.width;

}

break;

default :

break;

}

}

Source file you can find on the attached files.

Source:
movingMovieClipInTheContainer

Thank you for reading.

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>