Question

 <s:Button click="showMessage('<h1>Some message</h1>')" label="Как играть?" />

How to put an html message, in the handler, because I get an error of the parser that says, that inside click handlers there not be < symbols

Was it helpful?

Solution 3

You can also call your function in this way.

<s:Button label="Как играть?" >
        <s:click >
            <![CDATA[
                showMessage('<h1>Some message</h1>');
            ]]>
        </s:click>
    </s:Button>

OTHER TIPS

In the MXML-syntax, work standard methods of escaping special chars:

  1. prefixing it with the backslash character \
  2. using "HTML Number" code or also "ASCII Dec" (see table)
  3. Wrap your text in a CDATA tag.

e.g.:

<ns:myComp...>
    <ns:click>
        <![CDATA[
            // your AS3 code
        ]]>
    </ns:click>
    <ns:htmlText>
        <![CDATA[
            This is 14 point blue italic text.<br/>
            <b><font color="#000000" size="10">text</font></b>
        ]]>
    </ns:htmlText>
    ...

And I recommend you write a separate listener in <fx:Script> tag.

Escape them:

 <s:Button click="showMessage('&lt;h1&gt;Some message&lt;/h1&gtl')" label="Как играть?" />

That should get rid of compiler errors. Without knowing what the showMessage button does; it is tough to tell whether this will give you the desired results or not.

I'm not sure why you would want to do something like this.

It would be easier to change the handler to accept more properties:

protected function showMessage(heading:String, message:String):void {
     var message:String = '<h1>' + heading + '</h1><p>' + message + '</p>';
     // do something with message.
}
<s:Button click="showMessage('Title', 'Custom message.')" label="Click Me"/>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top