号分隔的一个或多个值的可选列表或数组,此列表或数组将插入到此数组中由 startIndex 参数指定的位置.
【查找数组中第一个相匹配的元素】 var array:Array = ["a", "b", "c", "d", "a", "b", "c", "d"]; var match:String = "b"; for(var i:int = 0; i < array.length; i++) { if(array[i] == match) { trace("Element with index " + i + " found to match " + match); //输出: Element with index 1 found to match b break; } }
【查找数组中最后一个相匹配的元素】 var array:Array = ["a", "b", "c", "d", "a", "b", "c", "d"]; var match:String = "b"; for(var i:int = array.length - 1; i >= 0; i--) { if(array[i] == match) { trace("Element with index " + i + " found to match " + match); //输出: Element with index 5 found to match b break; } }
【把字符串转成数组】 使用String.split()方法: var list:String = "I am YoungBoy."; var words:Array = list.split(" "); //以空格作为分隔符将字符串切割 trace(words); //输出: I,am,YoungBoy.
【把数组转成字符串】 使用String.join()方法: var myArr:Array = new Array("one", "two", "three"); var myStr:String = myArr.join(" and "); trace(myArr); //输出: one,two,three trace(myStr); //输出: one and two and three
【使用对象数组处理相关数据】 var cars:Array = new Array(); cars.push({make:"Mike", year:1997, color:"blue"}); cars.push({make:"Kelly", year:1986, color:"red"}); for(var i:int = 0; i < cars.length; i++) { trace(cars[i].make + " - " + cars[i].year + " - " + cars[i].color); } //输出: // Mike - 1997 - blue // Kelly - 1986 - red
【在数组中获取最小或最大值】 var scores:Array = [10, 4, 15, 8]; scores.sort(Array.NUMERIC); trace("Minimum: " + scores[0]); trace("Maximum: " + scores[scores.length - 1]);
【使用for ... in语句读取关联数组元素】 var myObject:Object = new Object(); myObject.name = "YoungBoy"; myObject.age = 20; for(var i:String in myObject) { trace(i + ": " + myObject[i]); } //输出: name: YoungBoy // age: 20 注意: for ... in循环不会显示对象所有的内建属性.例如,循环会显示执行期间新增的特殊属性,但是,不会列出内建对象的方法,即使都是储存在对象属性内.
【AVM(ActionScript Virtual Machine,虚拟机)和渲染引擎(Rendering Engine)】 AVM负责执行ActionScript程序,而渲染引擎则是把对象绘制在显示器上.
【指出容器的显示清单中有多 |