Avg. Rating 2.8

Problem

We want to pass variables from a query string into our Flex application.

Solution

Using PHP we can get the variables from the query string and load them in through our Flash object tag.

Detailed explanation

Let's say our Flex application lays on the page index.php
and we construct a query string as follows:
.../index.php?fname=nick&lname=sokach
we can use the GET method before our html tag in index.php that will grab our variables:
<?PHP
$first_name = $_GET['fname'];
$last_name = $_GET['lname'];
?>
<HTML>...
These variables can now be loaded into our Flex application by editing the AC_FL_RunContent method (which will be created in index.php by Flex Builder).  This method  is used to embed the Flash content into the page. Notice I have appended to the 'flashvars' variable.

AC_FL_RunContent(
"src", "showcaseBooklet",
"width", "100%",
"height", "100%",
"align", "middle",
"id", "showcaseBooklet",
"quality", "high",
"bgcolor", "#869ca7",
"name", "showcaseBooklet",
"flashvars",'historyUrl=history.htm%3F&lconid='+lc_id+'&fname=<?php echo $first_name ?>&lname=<?php echo $last_name ?>',
"allowScriptAccess","sameDomain",
"type", "application/x-shockwave-flash",
"pluginspage", "http://www.adobe.com/go/getflashplayer"
);

Now when the Flex application loads it will have "nick" set to fname and "sokach" set to lname.

Report abuse

Related recipes