FREE Flash CS3 Tutorials
In This Flash CS3 Tutorial you will learn how to create functions
Gordon French is a professional Flash CS3 Programmer and Designer.
He also attends the Art Institute in Denver where he majors
in Interactive Media and Design.
You will find Flash Games, Flash CS3 Tutorials, and Lots of General FREE Flash tutorials.

Index.html
Flash_Concentration.html
new_in_3.html
Flash_Asteriods.html
what_is_AC.html
history_of_AC.html
Flash CS3 Tutorial Naming Basics
Flash CS3 Tutorial DragAndDrop
Flash CS3 Tutorial SoundBasics
Flash CS3 Tutorial Graphics
AC_index.html http://www.f2-4kids.com

ActionScript

Flash CS3 Tutorial, ActionScript 3.0 Basics?

StumbleUpon Toolbar


Functions
In Flash CS3 Functions enable ActionScript to reuse certain pieces of code over and over. You can define some set of action within a function and then call that function whenever you need the code to run.

When building a function you start the line of code with the word function then the name of the function (basically whatever you want), a pair of parentheses and curly braces. What you want the function to do is contianed inside the curly braces.
To call the function you simple need to call it by name, such as aName().

Construct a function
Click on the first key frame on the time line layer called actions and press F9 to open the actions panel.

ActionScript

then add the following code:

function textArea(){
var myText:TextField = new TextField();
myText.text = “F2 Training”;
this.addChild(myText);
};
textArea();

function textArea() creates a new function called textArea. var myText creates a new variable called myText, :TextField is data typing which tells flash and programs what type of data will be contained within the variable you just created.

= new TextField(); defines the variable myText as having the value of new TextField(); The next line of code myText.text = “F2 Training“. Is telling Flash that the variable myText has a .text property and that it’s value is “F2 Training“. This is basically the same as drawing a text field on the stage, naming it myText and then typing F2 Training inside that text field. The differance is that this text field is dynamically controlled and can be called on whenever it may be needed. The last line this.addChild(myText); simple adds the new text field myText to the stage and then places the value inside that text field.

Continue Smiley
Press Control-Enter to see what you created.

Ok, so lets make the text filed more useful by passing a set of parameters. A parameter is a quantity or value that defines a certain characteristic of the function. It will make sence as we continue. Return to the actions panel and modify the text already inplace. See Example

function textArea(parameter:String){
var myText:TextField = new TextField();
myText.text = parameter;
this.addChild(myText);
};
textArea(“this is a parameter“);

The word parameter in this case is a variable that you can name just about anything. Again, we see data typing in the form of :String. The data type string tells the programer and Flash that this variable will contain text. This parameter allows you to change the phrase every time you call the function.

Continue SmileyPress Control-Enter and test you movie.

Download Flash CS3 Source Files

Flash CS3 Tutorials, Copyright FrenchSquared 2008
ActionScript