flex - Capture Event Generated By Value Object in Component -
flex - Capture Event Generated By Value Object in Component -
let me seek explain best can.
i have component containing info grid next info grid column
<mx:datagridcolumn datafield="email" headertext="email address"> <mx:itemrenderer> <mx:component> <mx:vbox width="100%" horizontalscrollpolicy="off" verticalscrollpolicy="off" horizontalalign="center"> <mx:textinput id="tiemailaddress" width="95%" text="{data.email}" invalid="{data.isnotvalidemail(event);}" valid="{data.isvalidemail(event);}"/> <mx:emailvalidator id="validatoremailaddress" source="{tiemailaddress}" property="text" required="true" requiredfielderror="email address required."/> </mx:vbox> </mx:component> </mx:itemrenderer> </mx:datagridcolumn>
here's guts of value object:
[bindable(event="contactchange")] public class contactvo extends eventdispatcher { private var _email:string = "default email"; public var selected:boolean = false; public var edited:boolean = false; public var isnew:boolean = false; public var isvalid:boolean = false; public function contactvo() { } public function isnotvalidemail(e:event):void { isvalid = false; email = e.target.text; } public function isvalidemail(e:event):void { isvalid = true; email = e.target.text; } public function email():string { homecoming _email; } public function set email(value:string) : void { if (value != _email) { _email = value; edited = true; } dispatchevent(new event("contactchange", true)); } }
then in component, have gets called @ creationcomplete
addeventlistener("contactchange", processcontactchange);
through flex debugger, can see addeventlistener
statement called when component created, can see event fired value object when validation performed , value changes, processcontactchange
never called, assume event never making component.
any thought i've gotten wrong here? thanks!
[solution]
the conversation @flextras below helped deepen understanding of process , figure out disconnect in understanding. basically, changed innards of component's info column entry following:
<mx:textinput id="tiemailaddress" width="95%" text="{data.email}" invalid="{data.isnotvalidemail(event);}" valid="{data.isvalidemail(event);}" creationcomplete="{addlistener(data)}"/> <mx:script> <![cdata[ private function addlistener(data:object):void { var eventdispatcher:eventdispatcher = info eventdispatcher; eventdispatcher.addeventlistener("contactchange", outerdocument.processcontactchange); } ]]> </mx:script>
and removed event listener creationcomplete
method
when add together event listener have add together class fires event. in code, you're adding component contains datagrid. neither itemrenderer, datagrid, nor component containing datagrid fire event.
if component containing datagrid has access contactvo event, can hear straight on that.
otherwise, can add together event listener in itemrenderer.
if absolutely need execute code in component containing datagrid, itemrenderer should hear on value object event, fire event of it's own. create sure 'itemrenderer' event bubbles; , move display hierarchy.
flex events
Comments
Post a Comment