After passing the parameter, you can pass a value to the function when you call the function.
This value traces in the Output panel, as follows:
myFunc("This is what traces");
When you call the function, you should always pass the specified number of parameters unless
your function checks for undefined values and sets default values accordingly. The function
substitutes the passed values for the parameters in the function definition; if any parameters
are missing, Flash sets their value to
when you write ActionScript code.
You can also pass multiple parameters to a function, which can be as simple as the following:
var birthday:Date = new Date(1901, 2, 3);
trace(birthday);
Each parameter is separated by a comma delimiter. Many built-in functions in the
ActionScript language have multiple parameters. For example, the
the MovieClip class takes five parameters,
startDrag(lockCenter:Boolean, left:Number, top:Number, right:Number,
bottom:Number):Void
To pass a parameter to a function:
1.
Create a new Flash document and save it as parameters.fla.
2.
Add the following code to Frame 1 of the Timeline:
function traceMe(yourMessage:String):Void {
trace(yourMessage);
}
traceMe("How are you doing?");
The first few lines of code create a user-defined function called
single parameter,
passes the string value
3.
Select Control > Test Movie to test the Flash document.
The next example demonstrates how to pass multiple parameters to a function.
To pass multiple parameters to a function:
1.
Create a new Flash document and save it as functionTest.fla.
2.
Add the following code to Frame 1 of the main Timeline:
function getArea(width:Number, height:Number):Number {
return width * height;
}
The
function takes two parameters,
getArea()
undefined
. The last line of code calls the
yourMessage
"How are you doing?"
. You regularly pass parameters into functions
,
,
lockCenter
left
top
.
and
width
About functions and methods
method of
startDrag()
,
, and
right
bottom
, which takes a
traceMe()
function and
traceMe()
.
height
:
219
Need help?
Do you have a question about the FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH and is the answer not in the manual?