Lately I’ve been sick of the fact that I can’t query the get string, dont’ know how many other people are having this issue, in any case I wrote a class that doesn’t require you to have any javascript in the html, and it’s really simple to use, so here it is if you guys wanna improve it feel free, I’ll do what I can when I get the time. Which isn’t often.
TakeCare.
_Michael
import flash.external.ExternalInterface;
/*
* Created so that I can query values from the get string.
*
*@author: Michael Avila
*/
class URLQuery
{
// Instead of calling a function from javascript
// we will build the function in flash and call it
private var get_url_function:String = "function get_url(){return window.location.toString();}";
// a multi-dimensional array that contains the name value pairs, index[0] is the name and index[1] is the value
private var name_value:Array;
/* constructor */
public function URLQuery()
{
name_value = new Array();
// here we are making the call to our function, and we are taking it's return value, then we are spliting
// it in half at the first ? and taking the right side of the string, then we are spliting into another array
// this array will be split up on all of our & symbols
name_value = ExternalInterface.call(get_url_function).toString().split("?")[1].split("&");
buildNameValues();
}
/*
* You pass in the value for the variable, and we will return it if it extists
* if it doesn't we will return null
*/
public function queryString( getVar:String ):String
{
for(var i:Number=0; i<name_value.length; i++)
{
if (name_value*[0] == getVar) return name_value*[1];
}
return null;
}
/*
* Builds are name_value array, simple parsing
*/
private function buildNameValues()
{
for (var i:Number=0; i<name_value.length; i++)
{
name_value* = name_value*.split("=");
}
}
}