RSS link icon

.

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".

cellphone vibrate animation with flash actionscript

 

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;
}

tomm says: 2008-08-28

pliz help me out. here is my output Error Scene=Scene 1, layer=Layer 3, frame=1:Line 17: The class or interface Chr(34)EventChr(34) could not be loaded. function shakeIt (event:Event):void { Total ActionScript Errors: 1 Reported Errors: 1

Admin Bob says: 2008-09-03

Hi tomm, It would be easier to see if you email me your source code, so I can see what you did wrong, (my guess is, you put a bracket wrong, or one to many or few).

ashish says: 2008-07-01

thanks.

Anube says: 2008-07-01

very nice, simple and clear enough
make money with photoshop - book