Actionscript movie clip randomly shake


In this Macromedia Flash tutorial you will learn how to use action script to make a movie clip shake really cool and useful effect, and made with just a few lines of code.


1.
This is a very small an fast feature, that doesn't take a lot of code, its easy to implement to any movie clip in flash so here it goes.

Make whatever movie clip you desire to apply this feature to, as you can see from the image below, i choose a text.

Photoshop Tutorial thumb picture


2.
Now make another movie clip with the same text just in black color, right click it and choose arrange -> bring to back and move it on top of the text from before so it looks like the shadow.

Photoshop Tutorial thumb picture


3.
Now we are ready to make the code for this function.
Click on the first text movie clip and go to the action script panel.

type in this code.

onClipEvent (load) {
cx = this._x;
cy = this._y;
}
onClipEvent (enterFrame) {
this._x = cx+(1+Math.random()*5);
this._y = cy+(1+Math.random()*5);
}

Let me explain it to you.

onClipEvent (load) {
cx = this._x;
cy = this._y;
}

this code is activated once when the movie is launched, then to variables is declared and set to the x and y coordinates for the movie clip.

onClipEvent (enterFrame) {
this._x = cx+(1+Math.random()*5);
this._y = cy+(1+Math.random()*5);
}

this code makes the movie clip shake, so it takes the movie clip (called this) and set its _x axis to where it is now + a random number between 5.
And the same for y axis.

So now the movie clip can move randomly around within the boundaries of current coordinates *5.

Now copy the code into the action script for the shadow movie clip to and you should be done.

0tutor.com rss feed