03.05.2013 Views

FLASH® LITE™ 2.x - Adobe Help and Support

FLASH® LITE™ 2.x - Adobe Help and Support

FLASH® LITE™ 2.x - Adobe Help and Support

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Usage 2: The following example deletes a property of an object:<br />

// create the new object "account"<br />

var account:Object = new Object();<br />

// assign property name to the account<br />

account.name = "Jon";<br />

// delete the property<br />

delete account.name;<br />

Usage 3: The following example deletes an object property:<br />

var my_array:Array = new Array();<br />

my_array[0] = "abc"; // my_array.length == 1<br />

my_array[1] = "def"; // my_array.length == 2<br />

my_array[2] = "ghi"; // my_array.length == 3<br />

// my_array[2] is deleted, but Array.length is not changed<br />

delete my_array[2];<br />

trace(my_array.length); // output: 3<br />

trace(my_array); // output: abc,def,undefined<br />

Usage 4: The following example shows the behavior of delete on object references:<br />

var ref1:Object = new Object();<br />

ref1.name = "Jody";<br />

// copy the reference variable into a new variable<br />

// <strong>and</strong> delete ref1<br />

ref2 = ref1;<br />

delete ref1;<br />

trace("ref1.name "+ref1.name); //output: ref1.name undefined<br />

trace("ref2.name "+ref2.name); //output: ref2.name Jody<br />

If ref1 had not been copied into ref2, the object would have been deleted when ref1 was<br />

deleted because there would be no references to it. If you delete ref2, there are no references<br />

to the object; it will be destroyed, <strong>and</strong> the memory it used becomes available.<br />

See also<br />

set variable statement<br />

do..while statement<br />

do { statement(s) } while (condition)<br />

Similar to a while loop, except that the statements are executed once before the initial<br />

evaluation of the condition. Subsequently, the statements are executed only if the condition<br />

evaluates to true.<br />

A do..while loop ensures that the code inside the loop executes at least once. Although this<br />

can also be done with a while loop by placing a copy of the statements to be executed before<br />

the while loop begins, many programmers believe that do..while loops are easier to read.<br />

Statements 175

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!