Cellphone vibrator with actionscript 3
In this flash actionscript and animation tutorial we will make a cellphone vibrate using actionscript and some simple calculations and random values.
And this is how the vibrating phone will look.
First we need to import an image of a cellphone, it can just be a jpg or any other supported image files, you can use photoshop or your favorite image manipulations software to cut away background as I did.
Now when you have imported the phone image to the stage, right click it, and convert it to a movie clip.
In the properties panel give it an instance name, I named mine "phone_mc".

Now we are ready to do the simple actionscript code for this animation effect, I have made some inline code descriptions for you to better understand the code.
You can just copy and paste the code into your own flash project and it should work.
// first we define the current positions of the phone, both x and y axis.
var posx:Number = phone_mc.x;
var posy:Number = phone_mc.y;
// here we make an eventlistenser to call the shake function with an enter frame event.
phone_mc.addEventListener(Event.ENTER_FRAME, shakeIt);
// here is the shake function
function shakeIt(event:Event):void {
// quite simple just changes the current phone position and takes a random number (7/8) to add to it.
phone_mc.x = posx+(Math.floor(Math.random()*7));
phone_mc.y = posy+(Math.floor(Math.random()*8));
// also a random rotation to make it more interesting.
phone_mc.rotation = Math.random()*10;
}