« Return to Thread: setText method on LzText class

setText method on LzText class

by Henry Minsky-2 :: Rate this Message:

Reply to Author | View in Thread

 I came across this code in the alert component

        <text name="alerttext" x="${parent.text_x}" y="${parent.text_y}"
            resize="true" text="${parent.text}" multiline="true">
            <method name="setText" args="t">
                super.setText(t);
                 ....


which gets a swf9 error about an incompatible override, and in fact that's true, LzText.setText is defined as
having a second optional arg

LzText.setText is actually deprecated, and it has the method signature

     function setText ( t, force = null){

So what is the right way for user code to override the text setter on LzText? It seems like for 
one thing you should not need to know about the magic second arg. I don't think we want people
to have to do

<method name="$lzc$set_text" args="v"> 
either.. 


Is the approved way to ask them to declare the setter as an attribute?

<text>
   <attribute name="text" setter="..."

So for alert code shown above, we need to move that text=${parent.text} constraint to the attribute declaration, and it becomes

        <text name="alerttext" x="${parent.text_x}" y="${parent.text_y}"
            resize="true" multiline="true">
            <attribute name="text" type="text" value="${parent.text}" setter="this.mySetText(text)"/>
            <method name="mySetText" args="t">
                ....
                super.setAttribute('text',t);
             </method>









--
Henry Minsky
Software Architect
hminsky@...

 « Return to Thread: setText method on LzText class

LightInTheBox - Buy quality products at wholesale price!