View Full Version : Flex + url + xml
Jerry62712
06-23-2009, 05:01 PM
Starting simple, how do you access the parameters passed to the URL of a FLEX webpage? I'm talking about this:
file:///C:/Flex Builder 3/FSCalc/FSCalc/bin-debug/FSCalc.html?xmlInput=<?xml version="1.0" encoding="UTF-8" ?><FSParm>HouseholdSize>6</HouseholdSize></FSParm>
accessing the parm "xmlInput":
<?xml version="1.0" encoding="UTF-8" ?>
<FSParm>
<HouseholdSize>6</HouseholdSize>
</FSParm>
Once I know how do to this, the next question will be how to parse the parm into it's value pairs:
"HouseholdSize" and the associated value of "6"?
Peter Cowling
06-23-2009, 06:34 PM
There are loads of xml tutorials. Here is one that should help (http://developer.yahoo.com/flash/articles/e4x-beginner-to-advanced.html).
Jerry62712
06-23-2009, 08:07 PM
Thanks for the c/site. Once the initial questions is answered, I'll be sure to re-read it with the eye towards using that with the data I dream of one day getting.
I'm afraid my questions is much more basic than you were thinking. As I can't get the data to begin with, there is no need to know how to parse it. I need to know how to get the URL string, specifically the parameters passed to the webpage. Once I have that then I'll need to parse it.
Sorry that I wasn't clear on it.
Peter Cowling
06-24-2009, 09:05 AM
URLLoader (http://theflashblog.com/?p=242) is the right way to go.
Jerry62712
06-25-2009, 03:05 PM
I liked the example Yahoo had, but first I have to get the data. If I were doing it in javascript, it would take one line:
location.pathname
or
document.referrer
would both access the information. I was hoping Flex would have something like that or a simple way to get the information.
Jerry62712
06-26-2009, 07:00 PM
Mark it done!
Here is the class I wrote that gets the query string part of an URL:
package DHSclasses {
import flash.external.*;
import mx.controls.Alert;
public class FSURLParse {
private var allURL:String;
private var queryString:String;
private var parseXML:XMLList;
// constructor (dummy)
public function FSURLParse() {};
public function getAllURL():String {
return allURL;
}
public function setAllURL():void {
allURL = ExternalInterface.call("window.location.href.toString");
Alert.show("**Testing** allURL=" + allURL,"All Url Test");
}
public function getQueryString():String {
return queryString;
}
public function setQueryString():void {
// for this application, the queryString will always begin in
// the 5th position (url=xxxx) and will be a single variable
// containing an XML string
var parmKey:String;
var parmValue:String;
var parmSeparater:int;
queryString = ExternalInterface.call("window.location.search.substring",1);
// separate the "key" ('url' in this case)
// from the "value" (xml string in this case)
parmSeparater = queryString.indexOf("=");
parmKey = queryString.substring(0,parmSeparater);
parmValue = queryString.substring(++parmSeparater);
// change the goofy "%20" to a space and other other codes
// to their normal representation
queryString = unescape(parmValue);
Alert.show("**Testing** unescaped query string=" + queryString,"decoded Query String");
// if we were getting multiple parameters, we would have to split
// them into an array based on the separation character "&"
// if(queryString) {
// var allParams:Array = queryString.split('&');
// var length:uint = params.length;
// }
// we could then look at the array to see the name/value
// for (var i = 0, index = -1; i < length; i++) {
// var keyValuePair:String = allParams[i];
// if((index = keyValuePair.indexOf("=")) > 0) {
// var paramKey:String = keyValuePair.substring(0,index);
// var paramValue:String = keyValuePair.substring(index+1);
// params[paramKey] = paramValue;
// }
// }
}
public function getParseXML():XMLList {
return parseXML;
}
public function setParseXML():void {
var testing:String = getQueryString().toString();
Alert.show("**Testing** query as string" + testing,"XML as string");
parseXML = getQueryString() as XMLList;
if (parseXML) {
Alert.show("**testing** parm length=" + parseXML.length(),"Test parm length");
var item:XML;
for each(item in parseXML) {
Alert.show("item:" + item.toXMLString());
}
}
}
}
}
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.