Flex Learning -- transfer value between two pages of flex

Source: Internet
Author: User

As we all know, Flex is mainly used for the development of B/S structure programs. Any development of this type has the problem of passing values between pages. Generally, the address modification method is used for B/s development, hiding form fields and other methods, but these methods are useless in flex because the models supported by Flex are different from common B/S development languages, the general B/S development language mainly uses the request/response model, while flex uses the event-driven model (this model is mainly seen in the C/S structure program ), so our form and other value passing methods are ineffective. How do we transmit data on two pages of this model? The following describes two common value passing methods:
1. Use externalinterface to call Javascript
A) This method uses the call method of externalinterface to call JavaScript Functions, and then modifies the address (somewhat similar to the address modification method). On the acceptance page, browsermanager is used to obtain the address bar information, and uses urlutil to intercept parameters.
B) Although this method is simple, it actually calls two languages, which brings some difficulties to writing.
Sender Page code (second.html ):
<? XML version = "1.0" encoding = "UTF-8"?>
<Mx: Application xmlns: MX = "http://www.adobe.com/2006/mxml" layout = "absolute">
<Mx: SCRIPT>
<! [CDATA [
FunctionKk ():Void{
VaRVAL: String = myparam. text;
Externalinterface. Call ("Function () {window. Location. href = 'HTTP: // localhost: 8080/send/page.html # param1 ="+ Val +"'}");}
]>
</MX: SCRIPT>
<Mx: textinput id = "myparam"> </MX: textinput>
<Mx: button name = "OK" Click = "KK ()" x = "185" label = "Submit"> </MX: button>
</MX: Application>
Receiving Page code (page.html ):
<? XML version = "1.0" encoding = "UTF-8"?>
<Mx: Application xmlns: MX = "http://www.adobe.com/2006/mxml" layout = "absolute" creationcomplete = "Init ()">
<Mx: SCRIPT>
<! [CDATA [
ImportMX. Managers. ibrowsermanager;
ImportMX. Managers. browsermanager;
ImportMX. utils. urlutil;
[Bindable]
VaRParam: string;
FunctionInit ():Void
{
VaRBM: ibrowsermanager = browsermanager. getinstance ();
BM. INIT ();
VaRO: Object = urlutil. stringtoobject (BM. fragment ,"&");
Param = O. param1;
}
]>
</MX: SCRIPT>
<Mx: textinput id = "Val" text = "{Param}">
</MX: textinput>
</MX: Application>
Ii. Use sharedobject (transfer of local shared object)
A) This object is similar to a cookie and stores the data to be transmitted in the export dobject object. In fact, the local machine is roughly located (Win2k and Win XP, the default path is C: /Documents and Settings/username/Application Data/Macromedia/Flash Player/# define dobjects (username is the user name of the machine) to generate a sol file. This object has a data attribute, you just need to put the key-value pairs of the data you want to transmit into it. You can directly read them locally next time.
B) Unfortunately, this object requires you to create and clear it by yourself, and be sure to force refresh when writing data; otherwise, data cannot be hashed.
Sender Page code (index.html ):
<? XML version = "1.0" encoding = "UTF-8"?>
<Mx: Application xmlns: MX = "http://www.adobe.com/2006/mxml" layout = "absolute">
<Mx: SCRIPT>
<! [CDATA [
FunctionS MIT ():Void
{
VaRParam: String = myparam. text;
// Create a global container dobject. If the global container is not used, remove the following "/". Once the cookie is removed, it can only be used by your application. Other applicaiton cannot be seen.
// Myparam is required to create a file named Cookie. Sol on the local machine
VaROBJ: Export dobject = export dobject. getlocal("Cookie","/");
OBJ. Data. Username = myparam. text;
OBJ. Flush ();
// Call urlreqstto redirect to the second.html page
VaRReqst: urlreqst =NewUrlreqst ();
Reqst. url= "Second.html ";
NavigatetoURL (reqst );
}
]>
</MX: SCRIPT>
<Mx: textinput id = "myparam"> </MX: textinput>
<Mx: button label = "Submit" Click = "s MIT ()" x = "177"> </MX: button>
</MX: Application>
Receiving Page code (second.html ):
<? XML version = "1.0" encoding = "UTF-8"?>
<Mx: Application xmlns: MX = "http://www.adobe.com/2006/mxml" layout = "absolute" creationcomplete = "Init ()">
<Mx: SCRIPT>
<! [CDATA [
[Bindable]
VaRParam: string;
FunctionInit ():Void
{
// Find the myparam. Sol file locally
VaROBJ: Export dobject = export dobject. getlocal ("Cookie","/");
// Read the data stored on the previous page
Param = obj. Data. Username;
// When it is used up, do not forget to delete the myparam. Sol file.
OBJ. Clear ();
}
]>
</MX: SCRIPT>
<Mx: textinput id = "mypar" text = "{Param}"> </MX: textinput>
</MX: Application>

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.