ActionScript 3.0 Lesson 16: Control and Navigate a Disc on Stage Using the Keyboard

Tue, Aug 18, 2009

ActionScript

ActionScript 3.0 Lesson 16: Control and Navigate a Disc on Stage Using the Keyboard



Click on Stage and use Keyboard Arrows
to Move the Disc Below!

This movie requires Flash Player 9

On this Switch Statement HD tutorial, Avraham creates a Flying Saucer on stage and using one single event listener on the code he moves the disc using the Keyboard arrow keys and the switch statement. This flash tutorial has the X FIles Theme as background music.

DOWNLOAD THE SOURCE FILE

DOWNLOAD THIS TUTORIAL TO YOUR HARD DRIVE

Here is the source code:

// Stage Keyboard Listener and Switch Example
// by Avraham Saltoun
// solutions at say-web dot com
// FREE TO USE COPY AND DISTRIBUTE

stage.addEventListener(KeyboardEvent.KEY_DOWN,MoveSaucer);

//This will set the compiler
//waiting for a key stroke, and then
// execute the MoveSaucer function

function MoveSaucer (event:KeyboardEvent):void
// the void states that the function returns no value
// but receives the value of the key stroke
{
switch (event.keyCode){

case Keyboard.RIGHT:
FlyingSaucer_mc.x = FlyingSaucer_mc.x+5;
break;
// x is the coordinate for the horizontal position
// break will exit the switch and wait for
// next key stroke.

case Keyboard.LEFT:
FlyingSaucer_mc.x -=5;
// “FlyingSaucer_mc.x = FlyingSaucer_mc.x-5″
// is the same as
// “FlyingSaucer_mc.x -=5;”
break;

case Keyboard.UP:
FlyingSaucer_mc.y -=5;
break;

case Keyboard.DOWN:
FlyingSaucer_mc.y +=5;
break;

//Thanks for Watching!
//!!!!!!!!!!!!!!!!!!
}
}

Related Articles:

, , , , , , , , , , , , , , , , , ,

Leave a Reply

Security Code:

AVA Trading Forex
WIX create a FREE website.
Try ACT! 2010 Today
Accept Credit Cards
UseNeXT Fast Downloads
For Free Stuff Click Here

Get Paid for Filling Surveys


Go Daddy $7.49.com sale 125x125 Huddle Collaboration
oDesk Certified Action Script Programmer oDesk Certified Adobe Flash CS3 Designer oDesk Certified Adobe Photoshop 6.0 Designer

Compare Web Hosting Services and Prices

web hosting - Web Hosting guide to popular hosts.

Twitter Followers