When moduleloader is used to load the module, if timer is used in the module to control the execution of a function, after the module is uninstalled, timer controls the execution of the function. For example:
The main application is index.mxml(moduleloaderwith leincluded; the module is mo_test.swf (mo_test.mxml). Use timermo_test.mxml in mo_test.mxml:
{
Timer. addeventlistener ("timer", timerhandler); timer. Start ();
}
Public Function timerhandler (E: timerevent): void
{
Run code
}
Solution:Define the status of the global variable storage module in the main application, that is, whether or not the module is loaded. Then in timerhandler, the following code is called to judge index. mxml:
Public var modulestate: Boolean = false;
.......
// Set modulestate to true before loading the module
This. modulestate = true;
.........
// Set modulestate to false when the module in moduleloader is switched or when the module is uninstalled.
This. modulestate = false;
In mo_test.mxml:
{
Timer. addeventlistener ("timer", timerhandler); timer. Start ();
}
Public Function timerhandler (E: timerevent): void
{
If (! This. parentapplication. modulestate)
{
Timer. Stop ();
Return;
}
Run code
}
Till now, when mo_test is uninstalled, timerhandler no longer runs. However, when loading mo_test again, the following error may be returned: the object @ ce19af1 cannot be converted to MX. messaging. Messages. iMessage. The specific reason is not detailed. Solution: add the following code to index. mxml:
Import MX. messaging. Messages. remotingmessage; private var RM: remotingmessage; // just define it. This is an inexplicable and amazing problem. There are some similar solutions when using DataGrid and tabnavigater in the module.