When i first started writing actionScript, i was heavily dependant on authoring in the "normal" mode... However i became increasingly annoyed at the dialog boxes which came up, since they didn't offer all that much support as to exactly what i could put into the "editable" area's. Hence i took it upon myself to understand the structure of the text that the "normal"mode would write for me, and soon realized that it was alot easier to type the text in using the "expert" mode. In addition there are alot of benefits to authoring in the expert mode, since there is a lot of functionality that you can embedd into the actionScript, which you simply can't do soley through dependancy on the "normal" mode of authoring ActioScript.
So far we have covered the do's and don'ts of variables, and the proper way to utilize the dot syntax to navigate to and from objects and the way in which the dot syntax enables us to initiate an action, simply by attaching it to the end of a "path." However, this section should clear up the relationship of a path to initiating an action, in addition to the proper structure one needs to attach a n action to a button and a movie clip.
There are 4 basic types of structures:
1. evaluation
2. conditional (constructor)
3. function
4. new
Each of these items requires unique formatting. That is to say that the way in which each of these items are written, must be written according to a predefined "structure." The reason for this is that Flash recognizes the way in which the text which makes up actionScript is formatted (or structured) - and based on the structure, Flash will know how to behave properly. If the structure does not follow the precise structure, the actionScript will not work properly, and chances are, your movie will not work at all. Undersatnding the underlaying structure is perhaps the most valuable lesson to learn about actionScript, after all, the structure is what actually gives life to actionScript...
Essentially, ActionScript is a programming language. The best way to understand how a programming language "works" is to liken it to the english language... In that, in order to properly communicate in our language, we must follow certain "rules" - such as, spelling, verb and noun placement, conjunction (cunjunction junction, what's your function? ) and so on.
This is why understanding the rules or "structure" is important, it provides you with an understanding of why and how, and to what end you can manipulate the language in order to achieve the desiered results.
So i have broken down the structure of flash into 4 distinct categorues. Each category has it's own set of rules, and once you get the hang of the basic rules you will see that there are some ruleswhich you can bend and tweak, and get around, but it takes some experience to do this.
Even to this day i sometimes still refer to the "normal" mode of actionScript authoring to help get me started writing a couple of lines.
At any rate, lets start with item nnumber one:
Believe it or not most of the evaluation section has been covered through the previous sections of this tutorial. Evaluation is primarily the "guts" behind actionScript, in that it enables us to evaluate a variatey of things within our movie. Evaluation is being able to capture information about an object, and "save" that information so that we can pass that info on to something else, for future use.
The variable is fundamental to the evaluation process. Since the variable enables us to store or save pretty much any kind of information.
Evaluation consists of 4 basic elements:
1. variables, strings, numbers and balooean
In the variable section of this tutorial, we discussed how to properly construct (or structure) a variable. Below is a simple example of how we can create a variable by following the simple rule of "input = output." By placing an equal sign after a word, and assigning the value to a "string" (a group characters confined by quotes), a number, or a balooean value.
name = "bob"
age = 12
married = false
4. operators
Operators are usually things that one would use to with math:
= + - > < * /
There are operators which perform special tasks such as "is not" "is" "or" "and" and things like that these symbols are as follows:
is - ==
is not - !
or - ||
and - &
5. property's
Properties are directly associated to Movie Clips and the Flash movie as a whole. These enable us to obtain specific information about a movei Clip or about the Flash movie timeline and things related to "physical" objects in our flash movie. These items are things like:
_currentFrame
_x
_y
_xscale
_yscale
_width
_hieght
As you can see i have inserted an underscore before the items, this is the way that Flash recognizes that we are talking about a property, and not a string, or variable.
Taking this knowledge, we can apply it to the concept of evaluation. Which basically means that we want to determine the outcome of a mathematical function, or get specific information about an element in our movie.
Evaluation is also used in other structures we will be discussing soon. but for now lets just focus on applying evaluation to a variable.
Here are a couple of examples which show how we can use evaluation to perform a mathematical function, or obtain information about a movie clip.
age = 12 + 21
location = _root.football._x
size = _root.football._hieght
So you can see that on the right hand side of the variable there are items which utilize Flash's ability to perform mathematical functions, or use the dot syntax to navigate to a movie clip and obtain information about the movie clip you have specified.
To evaluate a property of a movie clip, you have to first tell Flash which movie it is that you want to evaluate, then, tell it to get specific information. This is done by using the dot syntax to navigate to the movie, then attach an evaluating command to the endo of the name of the movie clip you wish to obtain information about.
Here is how Flash thinks about the last example above (the size variable) "hmmm, ok, so there is a new variable named "size", and the value of "size" should be... hmmm, okay, so i should first go to the main stage (or the root) and look for something named "football"... ah yes, "football" is a movie clip. Okay, now, the next thing for me to do is... oh, the next item in this path is actually a property, and this property "_height" is directly attached to the item named "football" so i should determine what the hieght of the football is...so the value of the variable "size" is equal to the number which defines the hieght of the movie clip named "football" so "size" is a number, and from her on out, i will handle the variable "size" exactly how i normally handle a number, so that whenever somebody asks for the variable "size" they will get the height of the football.
Basically what we are doing in the above examples is to first define a variable (if you remember, flash will automatically determine that an item is a variable if it is followed by an equal sign.
The proper way to structure a variable is to place an equal sign after a word, and after the equal sign, you must have something. if there is nothing after the equal sign, flash will freak out. So by using the proper structure, we have esentially created a variable.
Evaluation
1. variables
2. strings
3. statement
4. command
5. property
Conditional
for ( init; condition; next ) {
}
Function
loadMovie ( url, target, method );
.getUTCSeconds()command
Property
_droptarget
Command
Key.ENTER
break;
.parentNode
New
new Array()
// The structure of ActionScript is set up identiacally to that of Javascript. So once you get the hang of actionScript, making the transition to JavaScript is a snap.