# Class \> Query Vars to Flash - ASP Style

**URL:** <https://forum.kirupa.com/t/class-query-vars-to-flash-asp-style/204317>\
**Category:** flash\
**Created:** [October 18, 2006, 8:40pm UTC](https://forum.kirupa.com/t/class-query-vars-to-flash-asp-style/204317 "2006-10-18T20:40:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![buginajar](https://avatars.discourse-cdn.com/v4/letter/b/f07891/32.png) [@buginajar](https://forum.kirupa.com/u/buginajar)\
**Post date:** [October 18, 2006, 8:40pm UTC](https://forum.kirupa.com/t/class-query-vars-to-flash-asp-style/204317/1 "2006-10-18T20:40:21Z")

</div>

I recently had a flash project that required me to get query string variables and found it cumbersome, however i found a query string class here on the forums originally created by MichaelxxOA over at [actionscript.org](http://actionscript.org). [http://www.actionscript.org/forums/s…31&postcount=2](http://www.actionscript.org/forums/showpost.php3?p=449131&postcount=2)

I reqrote it and structured it to act like **Request.QueryString()** familiar to those that have worked with asp and aspx.

I also added some functionality to datatype the variables as well. For example, and numeric variable value will become a number once it is pulled in and a true or false will be converted to Boolean.

Anyway, I figured I would share…

```auto

//External Interface Class
import flash.external.ExternalInterface;

class Request
{

    //STATIC PROPERTIES
    //----------------------------------------------
    
    //Switch to Load Vars if they haven't already been loaded
    private static var hasLoaded:Boolean = false;
    
    //Define Javascript Function
    private static var getURLFunction:String = "function get_url(){return window.location.toString();}";
        
    //Array to store values once they have been loaded.
    private static var values:Array = new Array();

    //CONSTRUCTOR
    //----------------------------------------------
    public function Request(){}
    
    
    
    //PUBLIC STATIC METHODS
    //----------------------------------------------
    //--Query String
    public static function QueryString(varName:String)
    {
        //Pull Valuse From Query String if you havent already.
        if(!hasLoaded)
        {
            hasLoaded = true;
            getValueArray();
        }
        
        return values[varName];
    }
    
    //--Get Values From Query String
    private static function getValueArray():Void
    {
        trace("]> Loading Variables from Query String.");
        var o:Array = new Array();
        
        //Call Javascript Function
        o = ExternalInterface.call(getURLFunction).split("?")[1].split("&");
        
        for(var i:Number = 0; i < o.length; i ++)
        {
            var tempName:String = o*.split("=")[0];
            var tempValue:String = o*.split("=")[1];
            
            trace(" - " + tempName + " = " + tempValue);
            
            if(!isNaN(Number(tempValue)))
            {
                //Datatype value as a Number
                values[tempName] = Number(tempValue);
                
            }else if(tempValue.toLowerCase() == "true" || tempValue.toLowerCase() == "false"){
                //DataType value as a Boolean
                values[tempName] = Boolean(tempValue);
                
            }else{
                values[tempName] = tempValue;
            }
        }
    }
    
}

```

This is how you would use it  
[FONT=Courier New]

```auto

var qsVar = Request.QueryString("varName");

```

[/FONT]

---

<div class="post-metadata">

**Author:** ![buginajar](https://avatars.discourse-cdn.com/v4/letter/b/f07891/32.png) [@buginajar](https://forum.kirupa.com/u/buginajar)\
**Post date:** [October 25, 2006, 8:14pm UTC](https://forum.kirupa.com/t/class-query-vars-to-flash-asp-style/204317/2 "2006-10-25T20:14:48Z")

</div>

UDPATED: see [http://www.kirupa.com/forum/showthread.php?p=1985403#post1985403](http://www.kirupa.com/forum/showthread.php?p=1985403#post1985403)
