Monday, 2 June 2008

Key controls

This Flash tutorial will teach you about the basic key controls. This can adds interactivity to your objects as they are able to move on stage using the arrows keys. This tutorial uses Actionscript 2.0. For this tutorial I have used a free stock image of a cock which is available

Key controls

Step 1

Open a new lash document.

Step 2

Create/import your object on the stage. I used a free stock image but you can use whatever you wish.
Convert your object into a symbol by selecting F8.
Give your symbol an appropriate name, check movie clip and click ok.

Step 3

Using the selection tool (V) select your movie clip and give it an instance name. eg cock_mc

Step 4

On the timeline insert a new layer called "Actions".
Right click on the first frame and select Actions and enter the following code:

var speed:Number = 5;
_root.onEnterFrame = function() {
if (Key.isDown(Key.RIGHT)) {
cock_mc._x += speed;
} else if (Key.isDown(Key.LEFT)) {
cock_mc._x -= speed;
if (Key.isDown(Key.UP)) {
cock_mc._y -= speed;
} else if (Key.isDown(Key.DOWN)) {
cock_mc._y += speed;

**You change the amount of time/speed your object moves by altering the variable speed.

This code uses an onEnterFrame event handler to evaluate the conditional statements. Every time the statement is evaluated the cock_mc movie clip instance is moved to the relative position.

Step 5

Test your movie clip Ctrl + enter. Now sse the left, right, up and down arrow keys to control the movement of your object.

Your should now be able to move your object using the arrow keys. To limit the movements of an object on the stage, checkout the limit movements on the stage tutorial.

UPDATE: new key control in Actionscript 3.0.


tiku 23 June 2008 at 07:47  

all are very simple tutorials, excellent work.


  COPYRIGHT © 2014 · ILIKE2FLASH · Theme by Ourblogtemplates

Back to TOP