这里的代码:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()">
<mx:Script>
<![CDATA[
import mx.controls.TextInput;
private var txtArr:Dictionary = new Dictionary();
private var size:int;
public function init():void{
var arr:Array = ["aaaaaaa","bbbbbbbb","ccccccc","ddddddddddd","0","ffffffff","eeeeeee","0","ggggg","hhhhhh"];
var i:int = 0;
for each(var obj:String in arr){
var txt:TextInput = new TextInput();
txt.text = obj;
txt.id = "txt" + i.toString();
txtArr[i] = txt;
addChild(txt);
i++;
}
size = i;
}
public function sort():void{
for(var i:int; i < size - 1; i++){
var str:String = TextInput(txtArr[i]).text;
if(str==null || str.length==0 || str=="0"){
TextInput(txtArr[i]).text = TextInput(txtArr[i + 1]).text;
removeChild(txtArr[i]);
}
}
}
]]>
</mx:Script>
<mx:Button id="btn" label="Click Me" click="sort()"/>
</mx:Application>
我希望会有用。您可以在此处下载 Flex 项目。