Arrays are variables that store multiple values in a single variable name. So, an Array is a variable with an ordered list of values.
var array_name:Array = [val1, val2, ...];
var array_name = new Array(val1, val2, ...);
To create an empty Array, you can use any of these two expresions:
var m_ar:Array = []; OR var m_ar:Array = new Array();
var m_ar:Array = ['web site', 'coursesweb.net', 78];
// get the second item (with index 1)
trace(m_ar[1]); // Output: coursesweb.net
To access the first value, use index 0 (e.g., trace(m_ar[0]); will output "web site").var m_ar:Array = ['web site', 'coursesweb.net', 78]; // define a variable to be used for index var i:uint = 2; // create a variable which use an array item for its value var test = 4 + m_ar[i]; trace(test); // Output: 82- Because the value of "i" variable is 2, the expression m_ar[i] will access the third element in "m_ar" and return its value (78).
array_name[index] = new_value;If the array_name[index] element isn't defined in that array, will be added automatically with the "new_value". This method can be used when you want to add new elements in an array.
var m_ar:Array = ['web site', 'coursesweb.net', 78]; // changes the value of the first element m_ar[0] = 'tutorials'; // use "trace(m_ar)" to check the Array values trace(m_ar); // tutorials,coursesweb.net,78 // adds a new element in "m_ar" (fourth, with index 3) m_ar[3] = 'ActionScript'; // use "trace(m_ar)" to check the Array values trace(m_ar); // tutorials,coursesweb.net,78,ActionScript- "trace(array_name)" displays in the Output panel the values stored in array_name, separated by comma.
array_name.slice(index, 1)- "index" - is the index of the item you want to delete. The value of 1 specifies that one element will be deleted.
var m_ar:Array = ['web site', 'coursesweb.net', 78]; // delete the value of the third item in "m_ar" m_ar[2] = ''; // delete the second item in "m_ar" m_ar.splice(1, 1); // use "trace(m_ar)" to check the Array values trace(m_ar); // web site,
array_name.lengthIf in an Array, for example with three elements (with index 0, 1, and 2), you add a new elemant, but with a higher index that the next item should have, for example a fourth element, but with index 5, that Array will have 6 elements. ActionScript will automatically add the missing elements with an empty value, starting from the next index in array till the index of the new item.
var m_ar:Array = ['web site', 'coursesweb.net', 78]; // define a variable to store the number of items in "m_ar" var nrel:int = m_ar.length; // use "trace(nrel)" to check the number of items trace(nrel); // 3 // add a new element in array (fourth, but with index 5) m_ar[5] = 'marplo.net'; // updates number of items stored in "nrel" and check again with trace() nrel = m_ar.length; trace(nrel); // 6 // check to see all values in "m_ar" trace(m_ar); // web site,coursesweb.net,78,,,marplo.netAs you can notice, after the fourth value was added, with index 5, the "m_ar" array has 6 elements. The items with index 3 and 4 was automaticaly added, with empty value.
var m_ar:Array = ['web site', 78, 'marplo.net']; // set a number of 8 items in "m_ar" m_ar.length = 8; // define a variable to store the number of items in "m_ar" var nrel:int = m_ar.length; // use "trace(nrel)" to check the number of items trace(nrel); // 8 // set a number of 2 items in "m_ar" m_ar.length = 2; // updates number of items stored in "nrel" and check again with trace() nrel = m_ar.length; trace(nrel); // 2 // check to see all values in "m_ar" trace(m_ar); // web site,78
<table><tr> <th>Title 1</th> <th>Title 2</th> </tr></table>
.some_class { line-height: 150%; }
document.getElementById("id_button").onclick = function(){ window.open("http://coursesweb.net/"); }
$ar_dir = scandir("dir_name"); var_export($ar_dir);