create your own

Flash CS3 Tutorials, Functions

67
rate or flag 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




IT Admin, Everything Computer Related

  • CSS, How to understand inline and block level elements.

    Block level  elements are normally displayed as blocks with line breaks before and after. Examples of block level elements include paragraphs, headings, divs and block quotes. Inline elements are... - 4 months ago

  • CSS, How To tweak css for only Safari?

    If you have spent anytime dealing with CSS you have run into issues with a browser rendering code incorrectly. You may even have gone as far as to make several style sheets and use a browser check... - 4 months ago

  • CSS, How to Hide Styles from Older Browsers?

    Some older browsers, such as Netscape Navigator 4 and IE 4, have poor support for CSS. It is possible to hide styles from these browsers using specific media types and @import rules. All styles will... - 4 months ago

  • CSS, How to use @import styles

    @import Styles? Header and external style sheets also can import other style sheets using the @import rule. The @import rule must be placed before all other rules in the header or external style... - 4 months ago

  • CSS, How to use External Style Sheets!

    The third method of applying styles to  document involves linking to external style sheets. External style sheets are the most appropriate method for styling documents. If styles need to be... - 4 months ago

  • CSS, How to Use Header Styles

    Header styles also can be used to style the <p> element. The CSS rules can be placed in the head of the document using the style element. Like inline styles, header styles, header styles... - 4 months ago

  • CSS, How to Apply Inline Styles.

    CSS, Inline styles can be applied directly to elements in the HTML code using the style attribute. However, inline styles should be avoided wherever possible because the styles are added to the HTML... - 4 months ago

  • Twitter Weekly Updates for 2009-08-09

    New blog post: CSS, What is a <div> http://bit.ly/Sbfu # Flash, ActionScript tutorials on loops http://bit.ly/QMq8t # Great PHP Tutorial on using include and require. Include is a great way... - 4 months ago

CSS How to

  • Twitter Weekly Updates for 2009-11-22

    The maker of iFart is sending a message to Steve Jobs and Apple: http://digg.com/d31ARUx?t # An Open Appeal to Steve Jobs: http://digg.com/d31ARUx?t # Powered by Twitter Tools - 6 days ago

  • CSS, How to work with content areas.

    The content are of a box can be given width, height, and color. Width and height can be specified in points (equal to 1/72 of an inch), picas (equal to 12 points), pixels, ems, exes, millimeters, centimeters, inches, or percents. - 2 months ago

  • Twitter Weekly Updates for 2009-09-20

    My Farmville is broken, cant access, gifts, market, or ribbons # Farmville and zynga are a rip off. Watch out. There are still some glitches in the game and zynga told me to bad Im unimportant. # wouldnt it make more since for a developer to fix broken issues rather then add new features. Well not farmville, [...] - 2 months ago

  • Twitter Weekly Updates for 2009-09-06

    I need 5 more neighbors on FarmVille help me out. http://bit.ly/tLsni # looking for flash tutorials and how to guides check out – http://frenchsquared.com/ # Powered by Twitter Tools - 3 months ago

  • Twitter Weekly Updates for 2009-08-30

    New version of Wordpress theme adStyle is live at: http://wordpress.org/extend/themes/adstyle # Just finished installing OS X 10.6 on my new Solid State drive. Very impressed, seems noticeably faster. # I need more neighbors on Farmville for Facebook. Hit me up as a friend. http://bit.ly/tLsni # playin farmville on my macbook 10.6 and new solid sate sata II [...] - 3 months ago

  • CSS, How to properly use Border Styles.

    The border properties specify the width, color and style of the border of an element. Shorthand border properties include border-top, border-bottom, border-right, border-left and border. - 3 months ago

  • CSS, How to Padding Padding and more Padding

    Padding can be applied to the outside edges of the content area of any block level or inline element. Padding creates the space between the edge of the element and its content. - 3 months ago

  • Twitter Weekly Updates for 2009-08-23

    Wordpress liked my theme. They have asked that a make a few revisions and resubmit. Sounds like my theme may get accepted! # how long does it normally take for wordpress to get back to you after submitting a theme? # Just finished update my first wordpress theme http://wordpress.org/extend/themes/adstyle # New wordpress theme made for adsense check it out [...] - 3 months ago

Print   —   Rate it:  up  down  flag this hub

Comments

RSS for comments on this Hub

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