Introduction to ActionScript 2.0

Those of you who have been coding with earlier versions of Flash such as Flash MX or before will find this section very useful; it covers some of the differences and advantages in ActionScript 2.0.

But not to worrythose of you still wanting to code in ActionScript 1.0 (Flash MX style coding) still have this option as you can see in Figure 8.2. Go to the publish settings; choose File>Publish Settings (Ctrl+Shift+F12), choose the Flash tab, and choose ActionScript 1.0. Be warned, it's not only possible, but likely that you will run into conflicts using ActionScript 1.0 with ActionScript 2.0 anywhere in the file. You can also see which version of ActionScript you are running in your file by selecting the stage and viewing the Properties Inspector as in Figure 8.3.

Figure 8.2. Use the Publish Settings dialog box to set which version of ActionScript you would like your file to support.

Figure 8.3. Use the Properties Inspector to quickly see which version of ActionScript you are using.

But the first feature we will discuss in ActionScript 2.0 is the case-sensitive structure.

Back in ActionScript 1.0, you could easily declare a variable myVariable and then call it by using MYVARIABLE; they both would have been considered the same variable. But now, all internal and external ActionScript is case sensitive.

For example, in ActionScript 1.0, you would write this:

 var myVariable = "test"; trace(MYVARIABLE); //Output: test 

In ActionScript 2.0, you would write this:

 var myVariable = "test"; trace(MYVARIABLE); //Output: undefined 

It is the same when passing parameters into functions:

 //create the function function myFunction(sample){      trace(SAMPLE); } //call the function myFunction("testing"); //Output: undefined 

As you can see, in ActionScript 2.0, the preceding code would return undefined. So remember to always check your letter casing.

Declaring Variables and Instance Names

Other features of ActionScript 2.0 that bring it more in line with ECMA standards are shown in Table 8.1.

Table 8.1. New Features of ActionScript 2.0

ActionScript 2.0

ActionScript 1.0

Undefined numbers

Resolve to NaN.

Resolve to 0.

Undefined strings

Resolve to undefined.

Resolve to empty strings, "".

When converting strings to Boolean values

Resolve to TRue if the string has a length greater than 0, false if the string is empty.

The string is first converted to a number, and the Boolean value is TRue if the number is a non-zero number, false if it is zero.

Macromedia Flash Professional 8 Unleashed
Macromedia Flash Professional 8 Unleashed
ISBN: 0672327619
EAN: 2147483647
Year: 2005
Pages: 319 © 2008-2017.
If you may any questions please contact us: