Communication between Flex module and Application

后端 未结 3 1472
Happy的楠姐
Happy的楠姐 2021-01-27 23:36

Ok, modules in Flex are popular but I have no idea why documentation and examples on the different uses of Flex modules can be so scarce.

Anyway, for this question, I wi

3条回答
  •  清酒与你
    2021-01-28 00:18

    You can't really guarantee that the deptID will be set when creationComplete runs--it sounds like you're waiting for a server result--so this is probably not the best way to handle it.

    One of the things you need to be careful of is directly referencing the full Module Class from the main Application, because the point of modules is that you should not compile in the module Class into the main Class (to reduce file size/load times).

    So what you might want to do is create an Interface. This creates a "contract" between the main application and the Module without carrying all the implementation code with it. That might look something like this

    public interface IEmployeeModule {
        function set deptID(value:int):void;
    }
    

    Then, your Module might have code that's something like 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, you can determine if you still care
    }
    

    Note that, though global variables seem like a wondermous idea when your project is small, they are a very bad habit to get into. It can be almost impossible to repair a project that starts out with these and then grows to the point that no one can figure out exactly which of the hundreds or thousands of Classes that have access to a variable are changing it in the wrong way at the wrong time.

    You ESPECIALLY don't want to use global variables with Modules, as they can cause really bad problems when the modules start fighting over the definition.

提交回复
热议问题