Flex 4.0 solves the problem of using timer to refresh data in real time in the module and executing it after uninstalling the module.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.