Writing Scripts with ActionScript > Opening Flash 4 files
Opening Flash 4 filesActionScript has changed considerably with the release of Flash 5. It is now an object-oriented language with multiple data types and dot syntax. Flash 4 ActionScript only had one true data type: string. It used different types of operators in expressions to indicate whether the value should be treated as a string or as a number. In Flash 5, you can use one set of operators on all data types.
When you use Flash 5 to open a file that was created in Flash 4, Flash automatically converts ActionScript expressions to make them compatible with the new Flash 5 syntax. You'll see the following data type and operator conversions in your ActionScript code:
![]() |
The = operator in Flash 4 was used for numeric equality. In Flash 5, == is the equality operator and = is the assignment operator. Any = operators in Flash 4 files are automatically converted to == . |
![]() |
Flash automatically performs type conversions to ensure that operators behave as expected. Because of the introduction of multiple data types, the following operators have new meanings: |
+, ==, !=, <>, <, >, >=, <= |
|
![]() |
In Flash 4 ActionScript, these operators were always numeric operators. In Flash 5, they behave differently depending on the data types of the operands. To prevent any semantic differences in imported files, the Number function is inserted around all operands to these operators. (Constant numbers are already obviously numbers, so they are not enclosed in Number ). |
![]() |
In Flash 4, the escape sequence \n generated a carriage return character (ASCII 13). In Flash 5, to comply with the ECMA-262 standard, \n generates a line-feed character (ASCII 10). An \n sequence in Flash 4 FLA files is automatically converted to \r . |
![]() |
The & operator in Flash 4 was used for string addition. In Flash 5, & is the bitwise AND operator. The string addition operator is now called add . Any & operators in Flash 4 files are automatically converted to add operators. |
![]() |
Many functions in Flash 4 did not require closing parentheses, for example, Get Timer , Set Variable , Stop , and Play . To create consistent syntax, the Flash 5 getTimer function and all actions now require closing parentheses. These parentheses are automatically added during the conversion. |
![]() |
When the getProperty function is executed on a movie clip that doesn't exist, it returns the value undefined , not 0, in Flash 5. And undefined == 0 is false in Flash 5 ActionScript. Flash fixes this problem when converting Flash 4 files by introducing Number functions in equality comparisons. In the following example, Number forces undefined to be converted to 0 so the comparison will succeed: |
|
Note: If you used any Flash 5 keywords as variable names in your Flash 4 ActionScript, the syntax will return an error in Flash 5. To fix this, rename your variables in all locations. See Keywords.