Flash Script – Showing Key Presses in Flash


type = 'application/x-shockwave-flash'
data = 'http://sitepointstatic.com/flash/keypress.swf'
width = '400'
height = '400'
bgcolor = 'black'
>

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.

Free book: Jump Start HTML5 Basics

Grab a free copy of one our latest ebooks! Packed with hints and tips on HTML5's most powerful new features.

No Reader comments

Comments on this post are closed.