Toxiclab.org

Good Music Vibration Effect

7.7.2010, 18:24
Submited in: Flash | Total Views: 7656

In this flash tutorial I will show you how to create good music vibration effect using the action script 3 code and some special flash tips and tricks. This effect can be used for some web banner or for some simple presentation. Using this tutorial You will aslo learn how to create instance name, convert any photo into a Movie Clip Symbol and much much more.

Example:



Step 1

First, save the photo below that we will use for this lesson.





Step 2


Create a new flash document. Press Ctrl+J key on the keyboard (Document Properties) and set the dimensions of your document as the dimensions of photo (350x295px). Select any color as background color. Set your Flash movie's frame rate to 42 and click ok.

Step 3

Call the current layer music girl. Double-click on its default name (Layer 1) to change it. Press Enter once you have typed in the new name!

Step 4

Choose now File > Import > Import to stage (Ctrl+R) and import a photo that you just saved in step 1 into a flash stage. While the photo is still selected, go to the Align Panel (Ctrl+K) and do the following:

1. Make sure that the Align/Distribute to Stage button is turned on,
2. Click on the Align horizontal center button and
3. Click the Align vertical center button.



Step 5

While the photo is still selected, hit F8 key (Convert to Symbol) to convert it into a Movie Clip Symbol.



Step 6

While the new made Movie Clip is still selected, go to the Properties Panel below the stage. On the left side, You will find the Instance name input field there. Call this Movie Clip music_mc. See the picture below!



Step 7

Create a new layer above the layer music girl and name it action script. After that, select the first frame of layer action and go to the Action Script panel (F9). Then, enter this code inside the actions panel:

var coordX:Number = music_mc.x;
var coordY:Number = music_mc.y;
var timer:Timer = new Timer(12);

music_mc.buttonMode = true;

music_mc.addEventListener(MouseEvent.ROLL_OVER,startShake);
music_mc.addEventListener(MouseEvent.ROLL_OUT,stopShake);
timer.addEventListener(TimerEvent.TIMER, shakeImage);
 
function startShake(e:MouseEvent):void{
 timer.start ()
}

function stopShake(e:MouseEvent):void{
 timer.stop();
 music_mc.x = coordX;
 music_mc.y = coordY;
 music_mc.rotation = 0;
}

function shakeImage(event:Event):void {
 music_mc.x = coordX+ getMinusOrPlus()*(Math.random()*7);
   music_mc.y = coordY+ getMinusOrPlus()*(Math.random()*4);
   music_mc.rotation = getMinusOrPlus()* Math.random()*6;
}

function getMinusOrPlus():int{
 var rand : Number = Math.random()*3;
 if (rand<1) return -1
 else return 1;
}

We're done!

Test your vibration effect and enjoy!

Downlaod example

Are you a website owner?
Click here to register and submit your tutorials!

Browse by category


Most popular tutorials