Changing Elements in Arrays


Now that you know how to add and remove elements, let's discuss how to change them. We will create an array, trace it to see the original, change the first element to something else by using the index, and then trace it again to see the difference as shown in the following code:

 var my_array:Array = new Array("fName","lName"); trace(my_array); my_array [0] = "age"; trace(my_array); //output: fName, lName //        age, lName 

That was pretty simple. We just renamed the first element, just like renaming a variable. What's more, changing named array elements is just as easy, as shown here:

 var my_array:Array = new Array(); my_array.age = 24; trace(my_array.age); my_array.age = 25; trace(my_array.age); //output: 24 //        25 

The next section covers in greater detail nested arrays and how they can be used and manipulated.




Macromedia Flash Professional 8 Unleashed
Macromedia Flash Professional 8 Unleashed
ISBN: 0672327619
EAN: 2147483647
Year: 2005
Pages: 319

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net