actionscript 3 - Bindings not firing on Interface -
i have interface ibaseinterface
, class baseclass
.
when refer baseclass
via ibaseinterface
type bindings event names won't fire. normal binding (without event name) fires.
if refer baseclass
object
or baseclass
types ok , bindings fire.
ibaseinterface:
[event(name="proptwochanged", type="flash.events.event")] [event(name="propthreechanged", type="flash.events.event")] [bindable] public interface ibaseinterface extends ieventdispatcher{ function propone() :number; function set propone(value:number) :void; [bindable(event="proptwochanged")] function proptwo() :number; [bindable(event="propthreechanged")] function propthree() :number; }
baseclass:
[event(name="proptwochanged", type="flash.events.event")] [event(name="propthreechanged", type="flash.events.event")] [bindable] public class baseclass extends eventdispatcher implements ibaseinterface{ private var _propone:number = 0; public function propone() :number{ return _propone; } public function set propone(value:number) :void{ _propone = value; dispatchevent(new event('proptwochanged')); dispatchevent(new event('propthreechanged')); } [bindable(event="proptwochanged")] public function proptwo() :number{ return propone * 2; } [bindable(event="propthreechanged")] public function propthree() :number{ return propone / 2; } }
so, clarify problem:
proptwo
,propthree
bindings onibaseinterface
not fire.propone
binding ok, not have event name.- the problem occurs when accessing via interface, other types ok.
i have found 2 options fix this:
option 1
defining single [bindable(event="...")]
metadata on interface (not on function signatures), , dispatching single event update properties on interface.
ibaseinterface
:
[event(name="updatebindings", type="flash.events.event")] [bindable(event="updatebindings")] public interface ibaseinterface extends ieventdispatcher{ function propone() :number; function set propone(value:number) :void; function proptwo() :number; function propthree() :number; }
baseclass
:
[event(name="updatebindings", type="flash.events.event")] [bindable(event="updatebindings")] public class baseclass extends eventdispatcher implements ibaseinterface{ private var _propone:number = 0; public function propone() :number{ return _propone; } public function set propone(value:number) :void{ _propone = value; dispatchevent(new event('updatebindings')); } public function proptwo() :number{ return propone * 2; } public function propthree() :number{ return propone / 2; } }
this little clumsy think, if there lot of properties or lot of listeners in view resource intensive.
option 2
defining single [bindable]
(without event) on interface, , class directly dispatching propertychangeevent
.
ibaseinterface
:
[bindable] public interface ibaseinterface extends ieventdispatcher{ function propone() :number; function set propone(value:number) :void; function proptwo() :number; function propthree() :number; }
baseclass
:
[bindable] public class baseclass extends eventdispatcher implements ibaseinterface{ private var _propone:number = 0; public function propone() :number{ return _propone; } public function set propone(value:number) :void{ _propone = value; dispatchevent(new propertychangeevent(propertychangeevent.property_change, true, true, propertychangeeventkind.update, 'proptwo')); dispatchevent(new propertychangeevent(propertychangeevent.property_change, true, true, propertychangeeventkind.update, 'propthree')); } public function proptwo() :number{ return propone * 2; } public function propthree() :number{ return propone / 2; } }
this way best think, less intensive option 1 because required properties updated. cleans code, metadata can removed class , interface.
Comments
Post a Comment