Tuesday, August 12, 2008

Passing data with URL in flex

1) Include creationComplete="init(event);" in mx:Application

2) Include this script in mx:script tag
import mx.managers.BrowserManager;
import mx.managers.IBrowserManager;
import mx.utils.URLUtil;

private var bm:IBrowserManager;
[Bindable]
private var fName:String;
[Bindable]
private var lName:String;

private function init(e:Event):void {
bm = BrowserManager.getInstance();
bm.init("", "Welcome!");

/* The following code will parse a URL that passes firstName and lastName as
query string parameters after the "#" sign; for example:
http://www.mydomain.com/MyApp.html#firstName=Nick&lastName=Danger */
var o:Object = URLUtil.stringToObject(bm.fragment, "&");
fName = o.firstName;
lName = o.lastName;
}
]]>

3) use fName and lName with the text property of any control. for e.g.,
mx:Label text ={fName}

No comments: