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 + " ]]>";
精彩评论