开发者

How to do binding inside htmltext CDATA

开发者 https://www.devze.com 2022-12-24 10:19 出处:网络
I couldn\'t find a way to bind a variable inside the htmlText property of a Text component i want to be able to do something like this :

I couldn't find a way to bind a variable inside the htmlText property of a Text component i want to be able to do something like this :

<mx:Text id="bodyText"  styleName="bodyText">
<mx:htmlText >开发者_C百科
    <![CDATA[<img src='assets.OrangeRect' align='left' hspace='0' vspace='4'/>    Bonjour {UserData.name} ]]>

    </mx:htmlText>
</mx:Text>

i want to bind UserData.name


"But i still wonder if it is possible to be handled directly in mxml ? Especially if the binded variable changes i need it to be updated in the text component."
Hichem

You can bind the property to a function call so that whenever the bound value changes the result of the function call is used as the value to htmlText:

<mx:Script>
<![CDATA[

    function sayHello(userName:String):String
    {
        var text:String = "<![CDATA[<img src='assets.OrangeRect' align='left' hspace='0' vspace='4'/>    Bonjour " + userName + " ]]>";
        return text;
    }

]]>
</mx:Script>

<mx:Text id="bodyText" styleName="bodyText" htmlText="{sayHello(UserData.name)}" />

This is like a combination of the two - specify your binding in MXML, but have the value generated in the scripting section.


I'm not sure how it would be handled in MXML, but you can generate the full string in Actionscript:

bodyText.htmlText = "<![CDATA[<img src='assets.OrangeRect' align='left' hspace='0' vspace='4'/>    Bonjour " + UserData.name + " ]]>";
0

精彩评论

暂无评论...
验证码 换一张
取 消