Quantunet.com

Flash QuickSkills

Custom Function (statements)  

What Is A Function ?
Functions are used to group blocks of code so that they can be called with a simple statement and reused when nessecary.

Defining A Custom Function
To use a custom function it must first be defined. The term new function tell flash that a new function is being created.

function function_name() :datatype{
statements
}
  • "function_name" is the name given to the function. This is used to call the function later. Function should be named using names that describe what the function does. This makes it easyer to work with code
  • "datatype" is the type of data that you want the function to return. For example: "number" returns a result of the function in the form of a number or .....
  • "statements" are the actionscript statements that desacribe the actions that you want the function to perform.

Example I:
This function "sshow_text_when_called" is designed to display text in the actionscript output panel.

function sshow_text_when_called() :Void{
trace("Hello World.");
}

Each time the function is called the words "Hello World" appear in the output window.

Example II:

This function is designed to perform a simple mathematical calculation and return the result as a number.

function ncalculate_value() :Number{
130+22*9;
}

function n

Example III:
This function is designed to reset the position of the movie clip "car_mc" to the coordinates (150, 200) on the stage.

function reset_mc_position (car_mc:MovieClip) :Void {
car_mc._x = 150;
car_mc._y = 200;
}



Calling A Function
A function can be called by using its unique name

 

 


Parameters


Passing Parameters


Returning A Value From A Function

















   


How to create this rotation animation using the gotoAndplay actionscript
Download this .fla file

 

When tweening complex shapes:

  • Position shape hints on the shape in a clcokwise order starti ng from the top left corner


Note: Make sure the bitmap has been converted to a graphic or movie clip symbol before trying to create a tween.


© 2005 - 2007 Quantunet.com All Rights Reserved
Home | Terms of Use | Contact Us