0

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

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

进展顺利。

问题:我要做的是,如果假设 vartxt2 为空或具有特定值,则要删除的文本字段以及要向上移动的以下文本字段以代替已删除的文本字段。文本字段在另一个之下。

非常感谢你

4

1 回答 1

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 项目。

于 2013-07-20T21:01:57.800 回答