Macromedia Flash Professional 8 UNLEASHED [Electronic resources]

David Vogeleer, Eddie Wilson, Lou Barber

نسخه متنی -صفحه : 318/ 111
نمايش فراداده

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.