flex 4.6使用CDATA解析htmlText对象,仅显示最后一个对象

时间:2012-09-07 09:42:54

标签: flex dynamic-data cdata httpservice htmltext

我正在尝试使用<mx:text>字符串更新多个htmlText个对象。我遇到的问题是,当数据发生变化时,只有最后一个<mx:text>对象变得可见。

我是否遗漏了<mx:text>代码中的基本内容?

使用flex 4.6

thx Art

test1.html

<rtnA><![CDATA[ <font color="#0000ff" face="helvetica" size="15" >This is rtnA</font> ]]></rtnA>  
<rtnB>this is rtnB</rtnB>
<rtnC>this is rtnC</rtnC>
<rtnD><![CDATA[ <font color="#aa00aa" face="Arial" size="15" >This is </font><font color="#0000ff" face="helvetica" size="15" >rtnD</font> ]]></rtnD>

test1.mxml

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
           xmlns:s="library://ns.adobe.com/flex/spark" 
           xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
<s:layout>
    <s:BasicLayout/>
</s:layout>
<fx:Declarations>
    <s:HTTPService id="sendMe" url="http://myUrl.com/test1.html"
                   useProxy="false" method="POST"  resultFormat="object"  >
    </s:HTTPService>
</fx:Declarations>
<fx:Script>
    <![CDATA[


        import mx.core.FlexGlobals;
        import mx.geom.RoundedRectangle;
        import mx.rpc.events.ResultEvent;

        import spark.events.TextOperationEvent; 

        [Bindable]
        public var meta:Object;

        public function send_data(event:MouseEvent, funRtn):void {
            var params:Object = new Object();
            if(funRtn == "A"){
                sendMe.send();
                sendMe.addEventListener("result",getResA);
            }
            if(funRtn == "B"){
                sendMe.send();
                sendMe.addEventListener("result",getResB);
            }
        }

        public function getResA(event:ResultEvent) : void{
            sendMe.removeEventListener("result",getResA);
            status.text="getResA";
            meta = event.result;
            if(meta.hasOwnProperty("rtnA")){
                if(meta.rtnA != null){
                    rtnAtxt.htmlText = meta.rtnA; 
                }   
            }
            if(meta.hasOwnProperty("rtnD")){
                if(meta.rtnD != null){
                    rtnDtxt.htmlText=  meta.rtnD;
                }
            }       
        }

        public function getResB(event:ResultEvent) : void{
            sendMe.removeEventListener("result",getResB);
            status.text="getResB";
            meta = event.result;
            if(meta.hasOwnProperty("rtnB")){
                if(meta.rtnB != null){
                    rtnAtxt.htmlText = meta.rtnB; 
                }   
            }
            if(meta.hasOwnProperty("rtnC")){
                if(meta.rtnC != null){
                    rtnDtxt.htmlText=  meta.rtnC;
                }
            }       
        }


    ]]>
</fx:Script>

<s:SkinnableContainer id="lisc" width="100%" height="100%"  >
    <s:Label id="status">
    </s:Label>

    <mx:Text id="rtnAtxt"  x="20" width="150"  y="20" height="50" >
    </mx:Text>  

    <mx:Text id="rtnDtxt" x="20" width="150" y="20" height="50" >
    </mx:Text>  

    <s:Form id="myForm" x="20"  width="150" y="90"  height="100"> 
        <s:FormItem>
            <s:Button id="myButtonA" width="50" height="20"
                      label="go A" click="send_data(event, 'A')" />
            <s:Button id="myButtonB" width="50" height="20"
                      label="go B" click="send_data(event,'B')" />
        </s:FormItem>
        <s:FormItem>

        </s:FormItem>
    </s:Form>
</s:SkinnableContainer>

1 个答案:

答案 0 :(得分:0)

我认为您的代码没有任何问题。尝试在为每个侦听器指定的字段中打印出meta.hasOwnProperty值,以便您可以查看结果是否确实是您认为的结果。