Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Lets say you have a property <code>count</code> in some class. Easiest way is to generate setter and getter for this property and inside the setter to dispatch some custom event. </p> <pre><code>protected var _count:Number; public function get count():Number { return _count; } public function set count(value:Number):void { _count = value; dispatchEvent(new CountEvent(CountEvent.COUNT_CHANGED, value, true)); } </code></pre> <p>This is the custom event class:</p> <pre><code>public class CountEvent extends Event { public static const COUNT_CHANGED:String = "countChanged"; public var data:Object; public function CountEvent(type:String, data:Object, bubbles:Boolean=false, cancelable:Boolean=false) { super(type, bubbles, cancelable); this.data = data; } override public function clone():Event { return new CountEvent(type, data, bubbles, cancelable); } } </code></pre> <p>Note that if you need the value of the property and don't have reference to the object itself, you can create a data-object event. In order for this kind of custom event to work properly you need to override the clone method, which is used every time the event is re-dispatched.</p> <p>If you are looking for more advanced way of "observing" something is by using some custom code, e.g. <a href="http://code.google.com/p/flit/source/browse/trunk/flit/src/obecto/utility/observe/Observe.as?r=190" rel="nofollow">http://code.google.com/p/flit/source/browse/trunk/flit/src/obecto/utility/observe/Observe.as?r=190</a></p> <p>In either way you must decide whether you want to modify your class by adding a dispatcher (if your class is not a <strong>EventDispatcher</strong> subclass) and dispatch an event or use some other techniques. Another way is to make the property <code>[Bindable]</code> and use a binding between your property and some function to watch if something changes.</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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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