Showing posts with label querystring. Show all posts
Showing posts with label querystring. Show all posts

Tuesday, June 30, 2009

Send querystring variable to Flex application.

Hi man, This may help you to send a variable to to your Flex application while loading that in to the browser.

The url will be,
somename.com?utlVariable=lethimgo

Open the projectname.template.html from html-template folder. Declare a global variable, this will hold the value of the variable you pass through the URL

var javascriptVar = getquery_Value( 'utlVariable' );

//returns the value of the url variable
function getquery_Value(varName)
{
varName = varName.replace(/[\[]/,"\\[").replace(/[\]]/,"\\]");
var regexS = "[\?&]"+varName+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( window.location.href );
if( results == null )
return "";
else
return results[1];
}



Now you have to edit in 3 places... Pass the variable to the flex application as FlashVar.

// embed the Flash Content SWF when all tests are passed
AC_FL_RunContent(
"src", "${swf}",
"width", "${width}",
"height", "${height}",
"align", "middle",
"id", "${application}",
"quality", "high",
"bgcolor", "${bgcolor}",
"name", "${application}",
"allowScriptAccess","sameDomain",
"type", "application/x-shockwave-flash",
"pluginspage", "http://www.adobe.com/go/getflashplayer",
"FlashVars", "accessPermission="+javascriptVar
);

.........................................
...........
...........................



id="${application}" width="${width}" height="${height}"

codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">


width="${width}" height="${height}" name="${application}" align="middle"
play="true"
loop="false"
quality="high"
allowScriptAccess="sameDomain"
type="application/x-shockwave-flash"
pluginspage="http://www.adobe.com/go/getflashplayer"
FlashVars="accessPermission="+javascriptVar>




Now in the main file...

private function creationcomplete():void{

if(parameters.accessPermission=="lethimgo"){
//Access permitted, you may go now
}else{
// Access denied, go away...
}

}





Enjoy..!