Binding On A Class' Read Only Property

it2024-10-27  15

Do you have a class with read only properties?Need to bind to those properties?Getting: warning: unable to bind to property 'propertyName' on class 'com.example.package::ClassName'?

Add the Bindable metatag to your function and specify an event to be associated with it's update.

通过事件控制属性只读 package com.example.package {    import flash.events.Event;    import flash.events.EventDispatcher;        import mx.collections.ArrayCollection;    public class ClassNameextends EventDispatcher {        private var _myExposedVar:ArrayCollection;        public function ClassName() { }        public function set resultsObject(value:Object):void {            /* Do Stuff with resultsObject and update _myExposedVar */            this.dispatchEvent(new Event("ResultsUpdated") );        }        [Bindable(event="ResultsUpdated")]        public function get myExposedVar ():ArrayCollection {            return this._myExposedVar;        }    }}

通过赋值时发送事件,和捕捉事件,来控制属性只读。赋值即变成取值。

转载于:https://www.cnblogs.com/wuhenke/archive/2009/10/31/1593588.html

最新回复(0)