How to pass request Param data to the flex app

Source: Internet
Author: User

References

1. About flex HTML template wrapper (for more information in future ):

Http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf663fe-7fff.html

2. Creating a wrapper:

Http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf69084-7ecf.html

3. Use flashvar property to pass request Param data to flexapp:

Http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf626ae-7feb.html

 

4. the flex app gets the http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf69084-7e9c.html directly from the URL fragments

 

First, let's take a look at how to pass requestparam data to flexapp through flashvarproperty:

Step 1 create a flex Project

Step 2 open/html-template/index.template.html file, and find following Codes

VaR flashvars = {};


Step 3 add following 2 line codes below it

Flashvars. firstname = "Nick ";

Flashvars. lastname = "danger ";

If JSP page is used

Flashvars. firstname = "<% = request. getparameter (" firstname ") %> ";

Flashvars. lastname = "<% = request. getparameter (" lastname ") %> ";

You can also add Param in the file path of SwF to replace the above two lines of code (the following method works the same as the above two lines of code! Select one of the methods)

<SCRIPT type = "text/JavaScript">
VaR swfversionstr = "0 ";
VaR xiswfurlstr = "";
VaR flashvars = {};
VaR Params = {};
Params. Quality = "high ";
Params. bgcolor = "# ffffff ";
Params. allowScriptAccess = "samedomain ";
VaR attributes = {};
Attributes. ID = "flashvartest ";
Attributes. Name = "flashvartest ";
Attributes. align = "Middle ";
Swfobject. embedswf (
"Flashvartest.swf? Firstname = Nick & lastname = danger ",
"Flashcontent", "100%", "100% ",
Swfversionstr, xiswfurlstr,
Flashvars, Params, attributes );
</SCRIPT>

Note: The value of flashvars properties must be URL encoded, and the parameters contained in this value are connected "&".

Step 4 (optional) in index.template.html, you will also see the flash OBJECT tag <Object> In the <NoScript> file, to make it use flashvar, your <Object> should add flashvar Param

<Object ID = 'myswf 'classid = 'clsid: D27CDB6E-AE6D-11cf-96B8-444553540000' Height = '000000' width = '000000'>

<Param name = 'src' value}'flashvartest.swf '/>

<Param name = 'flashvars' value = 'firstname = Nick & lastname = danger '/>

.......

</Object>

Step 5. How to obtain data from flashvar In the flex app

<S: application... creationcomplete = "initvars ()">
<FX: SCRIPT> <! [CDATA [
Public var firstname: string;
Public var lastname: string;

Private function initvars (): void {
Firstname = mx. Core. flexglobals. toplevelapplication. Parameters. firstname;
Lastname = mx. Core. flexglobals. toplevelapplication. Parameters. lastname;
}
]> </FX: SCRIPT>

.....
</S: Application>

If you want to obtain all Params in flashvar, use the following code:

For (var I: String in flexglobals. toplevelapplication. Parameters ){
Label1.text + = I + ":" + flexglobals. toplevelapplication. Parameters [I] + "\ n ";
}

Step 6 run the flex app

Let's look at how to parse the param in the URL directly in the flex app:

The flex app uses browsermanager and urlutil to directly obtain the param in the URL.

Browsermanager is a singleton manager used to act as a proxy between a browser and an application. You can use it to access the URL in the browser's address bar, which is similar to accessing the document. Location attribute in JavaScript. These events are scheduled when the URL attribute is changed. The listener can then respond to, change the URL, and/or prevent other objects from obtaining the event.

Note: The Params in the URL follow "#", not "? "Later !! For example

Http://www.mydomain.com/Myapp.html # firstname = Nick & lastname = danger

Get the param code of the URL directly in the flex app

Import MX. Managers. browsermanager;
Import MX. Managers. ibrowsermanager;
Import MX. utils. urlutil;

Private function Init (): void {
VaR BM: ibrowsermanager = browsermanager. getinstance ();
BM. INIT ("", "Welcome! ");
// Call urlutil stringtoobject method to convert parameters to an object. The second parameter is the delimiter between Param.
// Assume that the URL is http: // xxx/myapp.html # firstname = Nick & lastname = danger, the separator is &
VaR O: Object = urlutil. stringtoobject (BM. fragment ,"&");
 
Label1.text =O. firstname + "" + O. lastname;
}

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.