Toxiclab.org

Air Balloon animation using the mouse moving and AS3

2.7.2009, 15:59
Submited in: Flash | Total Views: 14583

Using this thoroughly explained, detailed action script 3 flash lesson, you will see how to create cool air balloon animation using the mouse moving. You can use this animation for some presentation of flash banner. Using this lesson, you will also learn how to import any image into a flash stage, how to convert it into a Movie Clip Symbol, how to create instance name and much more.

Example:



Step 1

First, save the png image of air balloon below.





Step 2


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

Step 3

Call the current layer air baloon. 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 the image that you just saved in step 1 into a flash stage.

Step 5

While the image 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 AirBaloon_mc. See the picture below!



Step 7

Select now the first frame and go to the AS panel (F9). After that, enter this code inside the actions panel:

AirBaloon_mc.addEventListener(Event.ENTER_FRAME, do_stuff); 

function do_stuff(event:Event):void { 
var myRadians:Number = Math.atan2(mouseY-AirBaloon_mc.y, mouseX-AirBaloon_mc.x); 
var myDegrees:Number = Math.round((myRadians*180/Math.PI)); 
var yChange:Number = Math.round(mouseY-AirBaloon_mc.y); 
var xChange:Number = Math.round(mouseX-AirBaloon_mc.x); 
var yMove:Number = Math.round(yChange/20); 
var xMove:Number = Math.round(xChange/20); 
AirBaloon_mc.y += yMove; 
AirBaloon_mc.x += xMove; 
AirBaloon_mc.rotation = myDegrees+90; 


We're done!

Have a nice day!

Download example

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

Browse by category


Most popular tutorials