sign up!

Are you interested in learning, then sign up to be notified about new tutorials.

Email:


helpfull links


website solutions

Do you need a website?
We can have you online in 24 hrs for less then $100


master flash

Are you looking to learn flash? If so you need to check out Flash, the Information you need. You will find all of these tutorials, source files and more...

Get your copy today!

Flash, This Information you need

a few friends


follow Us On

FrenchSquared on Linked in

FrenchSquared on Twitter

Frenchsquared on Facebook



Flash Tutorial: Basic Functions

In Flash Functions enable ActionScript to reuse certain pieces of code over and over.

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 contained inside the curly braces.

Flash: 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 difference 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.

Press Control-Enter and test your flash tutorial.

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 scene as we continue. Return to the actions panel and modify the text already in-place. 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 programmer and Flash that this variable will contain text. This parameter allows you to change the phrase every time you call the function.

Press Control-Enter and test your flash tuorial.

Download Tutorials