In this thoroughly explained, detailed flash lesson, I will show you how to create picture vibrating effect using the AS code and mouse cursor. Using this lesson, you will also learn how to import any picture into a flash stage, how to convert it into a movie clip symbol, how to create instance name...Let's start!
Example:
Move the mouse cursor over the picture!
Step 1
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 picture. Select any color as background color. Set your Flash movie's frame rate to 32 and click ok.
Step 2
Find any picture which you like to use for this lesson.
Step 3
Call the current layer picture. 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 any picture into a flash stage.
Step 5
While the picture 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 picture_mc. See the picture below!

Step 7
Create a new layer above the layer picture and name it action. 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 = picture_mc.x;
var coordY:Number = picture_mc.y;
var timer:Timer = new Timer(12);
picture_mc.buttonMode = true;
picture_mc.addEventListener(MouseEvent.ROLL_OVER,startShake);
picture_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();
picture_mc.x = coordX;
picture_mc.y = coordY;
picture_mc.rotation = 0;
}
function shakeImage(event:Event):void {
picture_mc.x = coordX+ getMinusOrPlus()*(Math.random()*7);
picture_mc.y = coordY+ getMinusOrPlus()*(Math.random()*4);
picture_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 movie and enjoy!
Download source file (.fla)