Note that there are some explanatory texts on larger screens.

plurals
  1. POBinding to a read-only getter in AS3
    primarykey
    data
    text
    <p>Consider the following code:</p> <pre><code>[Bindable(event="ReportHeaderVO_effectiveFromDateJulian_updated")] public function set effectiveFromDateJulian ( value:Number ) : void { _effectiveFromDateJulian = value; dispatchEvent( new FlexEvent("ReportHeaderVO_effectiveFromDateJulian_updated") ); } public function get effectiveFromDateJulian () : Number { return _effectiveFromDateJulian; } public function get effectiveFromDate () : Date { return DateUtil.convertJDEJulianToDate(_effectiveFromDateJulian); } </code></pre> <p>There is a setter and a getter for the effectiveFromDateJulian which is a number representation of the date. I have provided a seperate getter which retrieves the same value, only converted to a proper date. It is a getter only though and relies on the setter for the numeric property to get its data from; so the effectiveFromDate property is effectively read-only.</p> <p>Data binding works on the effectiveFromDateJulian property; any updates work fine and notify everything properly. But when binding to the effectiveFromDate (getter only) property, I get a warning from the compiler: </p> <pre><code>warning: unable to bind to property 'effectiveToDate' on class 'com.vo::ReportHeaderVO' </code></pre> <p>Is there a way to make it possible to bind to this read-only property? I would assume I would have to dispatch an event on the setter that effects the read-only property, but I don't know what that would look like. </p> <p>This is a simple example, you could imagine a read-only property that depends on several setters to function and when any of those setters are updated the read-only property would need to fire a propertyChanged event as well. Any ideas? Please let me know if I need to clarify anything.</p> <p>Update: From the Adobe documentation here:</p> <p><a href="http://livedocs.adobe.com/flex/3/html/help.html?content=databinding_8.html" rel="noreferrer">http://livedocs.adobe.com/flex/3/html/help.html?content=databinding_8.html</a></p> <blockquote> <p>Using read-only properties as the source for data binding</p> <p>You can automatically use a read-only property defined by a getter method, which means no setter method, as the source for a data-binding expression. Flex performs the data binding once when the application starts.</p> <p>Because the data binding from a read-only property occurs only once at application start up, you omit the [Bindable] metadata tag for the read-only property.</p> </blockquote> <p>And this makes sense for constant values, but in this case the value does change, it just doesn't get set directly.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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