Getting url parameters in Flex
Recently I needed to access url parameters from Flex code. Here is an example how to do it. I am using ExternalInterface to get access to the browser (you cannot get parameters from Application.application.url).
Pay attention to the following note from doc:
Note: When embedding SWF files within an HTML page, make sure that the id and name attributes of the
I would also add additional character: ‘{’ - by mistake I use application name ‘app{’ and because of this could not access ExternalInterface (any method invocation returns null in this case)
You can use the following code to parse url and get dictionary that contains param names as key and param values as values.
function getUrlParamateres():Dictionary { var urlParams:Dictionary = new Dictionary(); var fullUrl:String = ExternalInterface.call(’eval’,'document.location.href’); var paramStr:String = fullUrl.split(’?')[1]; if (paramStr != null) { var params:Array = paramStr.split(’&’); for (var i:int = 0; i < params.length; i++) { var kv:Array = params[i].split(’='); urlParams[kv[0]] = kv[1]; } } return urlParams; }
Note: Probably better to use regex to replace parsing code to more simple statement (as long as regex is not too complex).
About this entry
You’re currently reading “Getting url parameters in Flex,” an entry on blog.widget-labs.com
- Published:
- 04.01.07 / 11pm
- Category:
- Adobe Flex
4 Comments
Jump to comment form | comments rss [?] | trackback uri [?]