Dot Syntax


With every programming language, there are rules and guidelines to using it correctly also known as its syntax. ActionScript is no exception to this; it has its own syntax called dot syntax.

The idea behind dot syntax is simple. When using properties, methods, or events with objects, the name of the property, method, or event must be separated from the object by a dot (period), like the following:

 myMovie_mc.stop();     //Stops the play head for the movie clip myString_str.length;     //this is the read only length property of a string myText_txt.text="test";     //sets the text of a text field myStuff_lv.onLoad=function(){};//declares the onLoad event for a LoadVars object 

As you can see, each time a property, method, or event is associated with an object, a dot is used to separate them. Also, if you are going to use a target path to a child movie clip, you must use dot syntax to separate the movie clip's instance names, like this:

 parentMovie.childMovie.gotoAndPlay(10);      //tell the child movie clip to go to frame 10 and play 

Another thing to notice about the preceding line of code is the use of the semicolon (;). In ActionScript, semicolons tell the ActionScript reader that the line is done. They are not necessary, but it is good practice to include them.

Another piece of the ActionScript language to mention is the use of parentheses () and curly brackets {}.

Parentheses are used for the following reasons:

  • To group segments of math together so that they are calculated first:

     trace(5+4*3);    //returns 17 trace((5+4)*3);    //returns 27 

  • To enclose parameters when creating or calling functions:

     function addNumbers(num1:Number,num2:Number):Number{      return num1+num2; } trace(addNumbers(1,3));     //returns 4 

  • To enclose a conditional:

     if(5 < 10){      trace("5 is less than 10"); } 

Curly brackets are used for the following reason:

  • To enclose ActionScript to run as a block of code:

     // with a conditional if(5 < 10){      trace("5 is less than 10"); } //with a loop while(i<10){      trace(i);      i++; } //with an event button.onPress=function(){      trace("the button was pressed"); } 

Those are some of the basic pieces that are used in ActionScript. Now we will begin to cover some of the basic objects and actions of ActionScript starting with the movie clip.




Macromedia Flash Professional 8 Unleashed
Macromedia Flash Professional 8 Unleashed
ISBN: 0672327619
EAN: 2147483647
Year: 2005
Pages: 319

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net