Flash CS3 Tutorials, Functions

74
rate this page

By frenchsquared

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

Flash CS3 source files

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

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.

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.

Press Control-Enter and test you movie.

looking for Source Files see link at top

Flash CS3 Tutorials, Copyright FrenchSquared 2008

  • Mysapce Mobsters

    Mobsters is a game I recently started playing on Myspace. It is a textual based game similar in design to the original Dungeons and Dragons. The difference is that Mosters is an online game with over 8 million users. Due...

  • Adobe Flex Builder Linux Public Alpha

    Update: Flex Builder Linux alpha 4 was released on 8/14/2008. Please download alpha 4. Welcome to the Adobe® Flex™ Builder™ Linux alpha on Adobe Labs. Flex Builder Linux is a plugin-only version of the Flex Builder that you can use...

  • MySpace and Mobsters

    If your into Myspace app's expecially Mobsters you need to check out, www.MySpaceFruitloops.com. It is a new and upcpming forum that has all kinds of information on your favority MySpace Apps. They have stats calculator and quick ad links for...

  • Photoshop Express Beta

    t Photoshop Express you can quickly and easily accentuate your photos with easy-to-use options for resizing, cropping, sharpening, and more. Make your photos pop with fun, eye-catching effects and enhancements. Then share your photos in My Gallery, where you can...

  • Improved Flash indexing

    Q: Which Flash files can Google better index now?We've improved our ability to index textual content in SWF files of all kinds. This includes Flash "gadgets" such as buttons or menus, self-contained Flash websites, and everything in between.Q: What content...

  —   Rate it:  up  down  [flag this hub]

Comments

RSS for comments on this Hub Small RSS Icon

No comments yet.

Submit a Comment

Members and Guests

Sign in or sign up and post using a hubpages account.


optional


  • No HTML is allowed in comments, but URLs will be hyperlinked
  • Comments are not for promoting your hubs or other sites

working