actionscript3在找到空文本字段时执行某些操作

时间:2013-07-20 18:41:41

标签: actionscript-3

在actionscript中,我有多个动态文本字段,它们使用print从php页面加载值。

...
vartxt1.text = receiveVars.phpVar1;
vartxt2.text = receiveVars.phpVar2;
vartxt3.text = receiveVars.phpVar3;
vartxt4.text = receiveVars.phpVar4;
vartxt5.text = receiveVars.phpVar5;
...

进展顺利。

问题:我试图做的是,如果让我们说vartxt2为空或具有特定值,则要删除的文本字段以及要移动的以下文本字段删除的地方。文本字段是另一个。

非常感谢

1 个答案:

答案 0 :(得分:0)

这里是代码:

<?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项目here