|
AS2 OOP: Changes and Additions
by senocular
New in Flash 7
The way Flash handles some variables when publishing
a swf to Flash 7 is used in a movie has changed
a little. These fairly minor, though important
changes are the no. 1 cause of complications when
porting Flash MX and earlier versions of movies
to Flash MX 04. Understand that you do NOT have
to convert your older movies for them to work
in the new Flash player. Even though they are
published to a lower format, the new player will
treat them accordingly as based on the version
of the swf. If they ain't broke, don't fix
them. These changes are only for when publishing to
the new Flash 7 format and applies to both ActionScript
1.0 and ActionScript 2.0 in that format.
When working in ActionScript 2.0, chances are
you are targeting the new player, so these need
to be understood. Here's
the run-down:
1. Case sensitivity
In a Flash 7 swf, all variables and keywords are
case sensitive. This means that myvariable is
not the same as myVariable. If used (as variables)
Flash will interpret each to have their own separate
values. This also means that attachmovie() will
no longer attach a movie from your library onto
the screen. The correct command is attachMovie()
with a capital M.
If you've been a
sloppy coder in the past, or just not keeping
correct capitalization (that doesn't necessarily
make you "sloppy"), this may be a problem.
Now you'll have to be sure to maintain consistency
with capitalization. With Flash objects and methods,
color coding can help. With your own variables,
you'll just have to keep to your guns and be consistent.
2. Undefined
variable values have changed
When you use a variable that has not been previously
defined somewhere in your script, Flash needs
to assume a certain default value for that variable.
This value is based on the context of where its
first used; is it being used as a number? as a
string? With Flash 6, this definition is 0 if
used as a number and an empty string (""), even though technically
the variable is still considered undefined. When
using Flash 7, these default values have changed.
Now, if an undefined variable is used as a number,
a NaN is given; if as a string, the string "undefined"
is given.
- var name, job;
- name = "George";
- trace(name+" works for "+job);
- var value;
- value++;
- trace(value);
3. String boolean
value has changed
Now with Flash 7 strings, as long as they aren't
empty, they have a boolean value of true. This means
that when they are seen in a true/false situation,
as long as the string has some value, it is seen
as being true. This includes strings like "0".
In Flash 6, strings are first converted to a number
and then evaluated to being if that number was
non-zero and false if not (i.e. if 0). Flash 6
will interpret "0" as being false; Flash
7 will not as it is not empty. To Flash 6 any
non-numeric string is false. To Flash 7, as long
as it has length, no matter if its numeric or
not, it's true. Look at the following chart for
examples.
|
Flash <= 6 |
Flash 7+ |
"" |
false |
false |
"0" |
false |
true |
"1" |
true |
true |
"text" |
false |
true |
4. Removed array
lengthening with string indexing
Though you may have never known it or even made
us of it, with Flash 6, you could extend the length
of an array if you tried assigning a value to
an index of that array outside of its length if
using a string that was not a specific array index
but could be parsed into one (i.e. a string that when used with parseInt would result in a number).
The string "5tuna", for example, is
not fully numeric so cannot specify a specific
index of an array. However, when parsed into a number, that value
becomes 5. If you tried to assign the index "5tuna"
of an array with a length less than 6 in Flash
6, that array's length would then reach out to
be 6 to account for the supposed index (even though,
oddly enough, no actual value would be assigned
to it). Now, when publishing your swf to Flash
7, that is not possible. Using strictly numeric
strings, however, is still acceptable and will
continue to work fine.
- myList = new Array(2);
- trace(myList.length);
- trace(parseInt("5tuna"));
- myList["5tuna"] = "anything";
-
- trace(myList.length);
- trace(myList[5]);
Now, with that out of the way, we can start focusing in more on Actionscript 2.0.
|