202
ActionScript language elements
Usage 3: The following example deletes an object property:
var my_array:Array = new Array();
my_array[0] = "abc"; // my_array.length == 1
my_array[1] = "def"; // my_array.length == 2
my_array[2] = "ghi"; // my_array.length == 3
// my_array[2] is deleted, but Array.length is not changed
delete my_array[2];
trace(my_array.length); // output: 3
trace(my_array); // output: abc,def,undefined
Usage 4: The following example shows the behavior of
delete
on object references:
var ref1:Object = new Object();
ref1.name = "Jody";
// copy the reference variable into a new variable
// and delete ref1
ref2 = ref1;
delete ref1;
trace("ref1.name "+ref1.name); //output: ref1.name undefined
trace("ref2.name "+ref2.name); //output: ref2.name Jody
If
ref1
had not been copied into
ref2
, the object would have been deleted when
ref1
was
deleted because there would be no references to it. If you delete
ref2
, there are no references
to the object; it is destroyed, and the memory it used becomes available.
See also
var statement
do..while statement
do {
statement(s)
} while (
condition
)
Similar to a
while
loop, except that the statements are executed once before the initial
evaluation of the condition. Subsequently, the statements are executed only if the condition
evaluates to
true
.
A
do..while
loop ensures that the code inside the loop is executed at least once. Although
this can also be done with a
while
loop by placing a copy of the statements to be executed
before the
while
loop begins, many programmers believe that
do..while
loops are easier to
read.
If the condition always evaluates to
true
, the
do..while
loop is infinite. If you enter an
infinite loop, you encounter problems with Flash Player and eventually get a warning message
or crash the player. Whenever possible, you should use a
for
loop if you know the number of
times that you want to loop. Although
for
loops are easy to read and debug, they cannot
replace
do..while
loops in all circumstances.
Summary of Contents for FLASH 8-ACTIONSCRIPT 2.0 LANGUAGE
Page 1: ...ActionScript 2 0 Language Reference ...
Page 1352: ...1352 ActionScript classes ...