Web
Article

Flash Script – Showing Key Presses in Flash

By Georgina Laidlaw


Download the sample files here.

1. Create a circle and make it into a movie clip. Name it "circle".

2. Right click the movieclip, and click "action" to go to the actions tab.

3. Insert the action below:

// action to move left  
onClipEvent (keyDown)  
{  
if (Key.isDown( key.LEFT))  
{  
_x-=10;  
}  
}  

// action to move right  
onClipEvent (keyDown)  
{  
if (Key.isDown( key.RIGHT))  
{  
_x+=10;  
}  
}  

// action to move up  
onClipEvent (keyDown)  
{  
if (Key.isDown( key.UP ))  
{  
_y-=10;  
}  
}  

// action to move down  
onClipEvent (keyDown)  
{  
if (Key.isDown( key.DOWN ))  
{  
_y+=10;  
}  
}

4. Done! Press ctrl+enter to test the movie, and press the arrow keys to see it work.

No Reader comments

Recommended
Sponsors
Because We Like You
Free Ebooks!

Grab SitePoint's top 10 web dev and design ebooks, completely free!

Get the latest in Front-end, once a week, for free.