actionscript 3 - Communication between Flex module and Application -
ok, modules in flex popular have no idea why documentation , examples on different uses of flex modules can scarce.
anyway, question, take classic employee/department example. have main.mxml contains mx:tabnavigator. each tab loaded s:moduleloader.
tables: employees {empid,empname,deptid}, deparments {deptid,deptname}
the tab navigator contains 1 tab (for our example) called employee. have employee.mxml module. in module, have datagrid populated employee details. use getemployees($deptid) function. function, may guess, returns me array of employees work in particular department.
outside tabnavigator, have departmentdropdownlist populated departments.deptname.
my objective load employee module when select particular department dropdownlist. have changehandler dropdownlist can give me deptid.
protected function departmentdropdownlist_changehandler(event:indexchangeevent):void { mydeptid=departmentdropdownlist.selecteditem.deptid; //var ichild:*=employeemodule.child imoduleinfo; }
now, million dollar question is: how pass deptid employees module. latter has employee_creationcompletehandler calls getemployees(deptid):
protected function employeesdg_creationcompletehandler(event:flexevent):void // need deptid departmentdropdownlist outside employee module. // if create global variable deptid, great! getemployeessresult.token=employeeservice.getemployeess(deptid); }
i have attempted use [bindable] variables without success.
i appreciate suggestions.
you can't guarantee deptid set when creationcomplete runs--it sounds you're waiting server result--so not best way handle it.
one of things need careful of directly referencing full module class main application, because point of modules should not compile in module class main class (to reduce file size/load times).
so might want create interface. creates "contract" between main application , module without carrying implementation code it. might this
public interface iemployeemodule { function set deptid(value:int):void; }
then, module might have code that's this:
protected var _deptid:int; public function set deptid(value:int):void { _deptid = value; var token:asynctoken=employeeservice.getemployeess(deptid); token.deptid = value;//in case department id changes, can determine if still care }
note that, though global variables seem wondermous idea when project small, bad habit into. can impossible repair project starts out these , grows point no 1 can figure out of hundreds or thousands of classes have access variable changing in wrong way @ wrong time.
you don't want use global variables modules, can cause bad problems when modules start fighting on definition.
Comments
Post a Comment