|
Function
Functions are a way of making code so you don't have to keep copying and pasting or rewriting the same code over and over in your document
You can call a function at any time in your program. When ever called it will execute the code you have written previously in your program. A basic example of this would be this. You can test this by pasting it into a frame.
function myFunction(){
trace("function has been called");
}
myFunction();
myFunction();
myFunction();
myFunction();
myFunction();
myFunction();
myFunction();

I will break it down now. First you must initialize your funtion by telling Flash what kind of action to do. In this case I am telling flash it is a function and it will do some actions that are placed inside the opening and closing brackets. But before you put the opening and closing brackers you must name your variable. In this case I have named it myFunction. Then put the parenthises to tell Flash what it will be passing through the function. In the previous code I did not pass anything. In the next code I will provide an example. You can test this by pasting it into a frame in a actionscript frame.
function myMessage(myMessage:String){
trace(myMessage);
}
var myString:String = "myString!";
myMessage(myString);

parameters must be variables and you must first initialize what kind of parameter will be put inside the inilazing function command.
|