Flash Script – Showing Key Presses in Flash

We teamed up with SiteGround
To bring you up to 65% off web hosting, plus free access to the entire SitePoint Premium library (worth $99). Get SiteGround + SitePoint Premium Now


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.

We teamed up with SiteGround
To bring you up to 65% off web hosting, plus free access to the entire SitePoint Premium library (worth $99). Get SiteGround + SitePoint Premium Now