Note that there are some explanatory texts on larger screens.

plurals
  1. POEquivalent of Flex DataBinding using Pure Actionscript
    text
    copied!<p>When Flex Sees Something Like This:</p> <pre><code>&lt;mx:Label text="Hello {MyVar} World!"/&gt; </code></pre> <p>It Must Translate That Somehow Into ActionScript. But What If I Need To Do Something Similar, At Runtime. How Can I Accomplish What DYNAMICALLY? WHEN I DO NOT KNOW THE CONTENTS OF THE BINDING TEMPLATE.</p> <p>In ActionScript it would need it to look <em>something</em> like this:</p> <pre><code>public function CustomDynamicBinding(StringToBind:String):Label { // *EXAMPLES* Of StringToBind: // "Hello {MyVar} World!" // "Product: {name} ${price}.00" // "{data.label}, {data.description}" // I've Written It This Way Because I DO NOT KNOW The Exact Text To Be Bound At Design Time. [Bindable] var Lab:Label=new Label(); Lab.text=??? return(Lab); } </code></pre> <p>How can I accomplish this kind of "Dynamic" binding... Where I <b>don't know</b> the value of "StringToBind" until runtime? For the purposes of this question we can assume that I do know that any variable(s) mentioned in "StringToBind", are guaranteed to exist at runtime.</p> <p>I already realize there are much more straightforward ways to accomplish this exact thing STATICALLY, and using only Flex/MXML. It's important for my project though that I understand how this could be accomplished without MXML.</p> <p>Doing This: lab.text = stringToBind.replace("{myVar}", str);</p> <p>Will NOT work because this simply assigns ONCE the value of "{myVar}" - (which may not even BE the variable referenced in "stringToBind"!!) to the label, and does not take into account when and if myVar changes! Wouldn't I need to somehow use something Like bindProperty?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload