Flash / Flex / ActionScript/Array/Push
Версия от 12:19, 26 мая 2010; (обсуждение)
Содержание
- 1 Appending Values to the End of an Array: The push() accepts one or more parameters and appends those values to the end of the array.
- 2 Items added to the list can be any expression.
- 3 push() method always appends new elements, even if all the existing elements have undefined values.
- 4 You are not limited to adding a single element at a time with push method
Appending Values to the End of an Array: The push() accepts one or more parameters and appends those values to the end of the array.
<source lang="java">
package{
import flash.display.Sprite; public class Main extends Sprite{ public function Main(){ var aEmployees:Array = ["A", "P", "C", "H"]; aEmployees.push("Ruth"); trace(aEmployees.toString());
} }
}
</source>
Items added to the list can be any expression.
<source lang="java">
package{
import flash.display.Sprite; public class Main extends Sprite{ public function Main(){ var temperature:int = 22; var sky:String = "sunny"; var weatherListing:Array = new Array( ); weatherListing.push(temperature, sky); trace(weatherListing); // 22,sunny } }
}
</source>
push() method always appends new elements, even if all the existing elements have undefined values.
<source lang="java">
package{
import flash.display.Sprite; public class Main extends Sprite{ public function Main(){ var aEmployees:Array = new Array(2); aEmployees.push("R", "H", "L"); trace(aEmployees.toString());//,,R,H,L } }
}
</source>
You are not limited to adding a single element at a time with push method
<source lang="java">
package{
import flash.display.Sprite; public class Main extends Sprite{ public function Main(){
var aEmployees:Array = ["A", "P", "C", "H"]; aEmployees.push("R", "H", "L"); trace(aEmployees.toString()); } }
}
</source>