Java and flex Study Notes (15) -- communication between applications and modules in flex

Source: Internet
Author: User

When creating files in Adobe flashbuilder 4.5, you can create application, module, and component files. I did not understand the three differences when I first started learning Flex. As I learned deeply, I now know the differences and usage of these three types, but I feel that I can only say what I want, so I will talk about the communication between the application and the module.


First, you must know that the module is compiled into a SWF file, and the module is loaded only when the application calls it. The benefits of doing so are obvious.

So how to call the module in the application? The following code creates an application file login. mxml:


<? Xmlversion = "1.0" encoding = "UTF-8"?> <S: Application xmlns: FX = "http://ns.adobe.com/mxml/2009" xmlns: S = "Library: // ns.adobe.com/flex/spark" xmlns: MX = "Library: // ns.adobe.com/flex/mx "pagetitle =" my online storage "preloader =" ases. util. loadingprogressbarutil "creationcomplete =" app_creationcompletehandler (event) "width =" 100% "Height =" 100% "> <FX: SCRIPT> <! [CDATA [protected function reg_account_clickhandler (Event: mouseevent): void {// todoauto-generated method stub center_canvas.visible = false; comonmodule. visible = true; If (registermoduleloader. url = NULL) {registermoduleloader. url = "module/registerusermodule.swf";} registermoduleloader. loadmodule (); // start loading module}]> </FX: SCRIPT> <mx: canvas width = "1060" Height = "100%" id = "center_canvas"> <mx: linkbutton label = "register a new account" width = "90" Height = "22" id = "reg_account" Click = "reg_account_clickhandler (event)"/> </MX: canvas> <mx: canvas width = "1060" Height = "100%" id = "comonmodule" visible = "false"> <s: moduleloader id = "registermoduleloader"/> </MX: canvas> </S: Application>

The result of this Code is that when you click "register a new account", load the module and hide the "register a new account" button. Note:Registerusermodule.swf is the SWF file generated by registerusermodule. mxml.

 

How does the module communicate with the application? Create a module FileRegisterusermodule. mxm,The Code is as follows:

 

<? Xmlversion = "1.0" encoding = "UTF-8"?> <S: module xmlns: FX = "http://ns.adobe.com/mxml/2009" xmlns: S = "Library: // ns.adobe.com/flex/spark" xmlns: MX = "Library: // ns.adobe.com/flex/mx "width =" 1060 "Height =" 100% "initialize =" registeruser_initializehandler (event) "creationcomplete =" events "> <FX: SCRIPT> <! [CDATA [protected function back_login_button_clickhandler (Event: mouseevent): void {// todoauto-generated method Stub this. parentapplication. center_canvas.visible = true; // set center_canvas on the parent page to visible this. parentapplication. registermoduleloader. unloadmodule (); // Uninstall this module}]> </FX: SCRIPT> <mx: linkbutton label = "existing account login" id = "back_login_button" Click = "back_login_button_clickhandler (event)"/> </S: module>

 

This part of the code is implemented by clicking the "login with an existing account" button to return to the parent page login. mxml, that is, you can uninstall this module page by usingThis. Parentapplication, you can get the instance of this parent page, and then you can operate the attributes of the parent page.

 

This code is part of a small project in my practice.


Original article, reproduced please indicate the source: http://www.dianfusoft.com/

 

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.