Back to Browse

Using Arrays in Action Script

3.9K views
May 6, 2013
2:12

This tutorial is about how to use arrays in action script. We will teach you how to use the push() function and also the splice function. Don't forget to check out our site http://howtech.tv/ for more free how-to videos! http://youtube.com/ithowtovids - our feed http://www.facebook.com/howtechtv - join us on facebook https://plus.google.com/103440382717658277879 - our group in Google+ Arrays in actionscript are collection of data of same data type. They are ordered information that can be manipulated and sorted. We will take a look at some of the simple functions in actionscript Arrays that can be used in manipulation. Step 1: Open a new project Open a new flash project of type ActionScript 3.0. All the manipulations that are described below are valid for arrays in ActionScript 3.0 only. Step 2: Declaration of an Array Open the Actions window to write the code. First is the declaration and the initialization of an actionscript array. There are two ways in which it can be done. Step 3: Tracing an Array Arrays can be traced. So add a trace() function to trace the elements in an array. When the movie is tested by pressing the CTRL+Enter key, the output window reads the elements present in the array. Step 4: Trace Individual elements Index of an array starts with 0 and individual elements of an array can be accessed using the index number. Let's look at some basic manipulations available: Individual elements of an array can be traced by mentioning the index number. Step 5: Add elements Individual elements can be added to the array. The easiest way is to type the array name followed by square braces that include the index number for the element to be added. This way the value will be added to the specified index. Let's consider the array myArray1, it contains 3 elements till index number 2. So if we add an element at index 6, it creates empty slots for the other indices. Step 6: Use the push() function When an element is added to the existing index number, the existing value is overwritten by the new value. Hence, this is not the preferred way of programmers. To add elements at the end of the array list, Push() function is preferred over the above said method. Step 7: Remove elements from an array To remove elements from an array, Splice() is the function used. It takes in two parameters: the starting index and the number of elements to be deleted. If the number of elements is not specified, it deletes all the elements of the index from the starting index. Thus, when myArray1 is spliced from index1 till the next 2 objects, sample2 and sample3 are the elements removed from the Array. Pop() is another function that can be used to delete the last element of the array. Conclusion These are some functions used to add and delete elements from an array. There is a property that determines the length of the array. reverse() is a function that reverses the occurrence of the elements. The change made by the function is permanent. The elements are changed of their index number as well.

Download

0 formats

No download links available.

Using Arrays in Action Script | NatokHD