Avg. Rating 3.3

Problem

Once the Flex application is compiled as SWF, you might want your SWF to behave differently based on the data passed or you might want to just display the data in your application.

Solution

You can pass data to compiled Flex application in various ways

Detailed explanation

You can pass data to Flex/Flash application during time as either Flash vars, query strings or URL fragments.

Passing data as Flash vars

To pass data as Flash vars, you should add the data as key value pairs in the HTML wrapper of the application.
Reading the Flash vars from Flex application is very simple, you should use Application.application.parameters variable, this variable is Object type. Your Flash vars will be added to this object. If you added a Flash var whose key is "key1", you will access this Flash var as Application.application.parameters.key1.
You can find more details at this URL: http://livedocs.adobe.com/flex/3/html/passingarguments_3.html

Passing data as query strings

To pass data as query strings, you should add the data as key value pairs to the src property of the SWF file in the HTML wrapper file. You will access these values the same way you access the Flash vars. More details regarding this can be found at this URL: http://livedocs.adobe.com/flex/3/html/passingarguments_3.html

Passing data as URL fragments

Above two methods allow to pass the data from the HTML wrapper, this method of passing the data allows you to pass data to the application in the URL pointing to the HTML file in which you have the SWF file of the application embed.

All you have to do is to add a "#" to the URL followed by your data as key value pairs to the URL. For example to pass "key1" with "value1" to your application, your URL will look like this http://www.yourdomian.com/webappcontext/yourhtml.html#key1=value1.
To access this from your application you will use BrowserManager class and the URLUtil class. BrowserManager's fragment method will give you the string after "#" in the URL. So, fragment property will have key1=value1 in our case.
You will use URLUtil class stringToObject method to get a object based on the BrowserManager's fragment value. In our case object returned by stringToObject function will have "key1" as property and "value1" as its value. You can find more details at this URL: http://livedocs.adobe.com/flex/3/html/deep_linking_5.html#245869

Report abuse

Related recipes