views:

590

answers:

3

In my Flex application I am able to read the variables using something like /flexapp.html?name=josh with no problems. However, this is because I go into the URL and type in the variables by hand. Is there anyway in the code to dynamically append the variable part "?name=josh" ? For example, like retrieving the url and then adding that and then pointing to it?

A: 
var myUrl:String = "/flexapp.html";
var myNameVar:String = "josh";
var myVar:String = "?name=" + myNameVar;
myUrl += myVar;

URLs are just strings, so you can use any string methods with them (regex concatenation, etc)

Joel Hooks
+1  A: 

Or, if you're using a URLRequest, you can format it this way:

package {
    import flash.display.Sprite;
    import flash.net.navigateToURL;
    import flash.net.URLRequest;
    import flash.net.URLVariables;

    public class URLVariablesExample extends Sprite {

        public function URLVariablesExample() {
            var url:String = "http://www.[yourDomain].com/application.jsp";
            var request:URLRequest = new URLRequest(url);
            var variables:URLVariables = new URLVariables();
            variables.exampleSessionId = new Date().getTime();
            variables.exampleUserLabel = "guest";
            request.data = variables;
            navigateToURL(request);
        }
    }
}

So long as you're using the get method, which is the default.

quoo
Thanks for the code, it's almost exactly what I want to do. However, navigateToUrl seems to open a new window each time. Is there anyway I can just refresh the current window?
joshholat
navigateToURl accepts a second parameter, so navigateToURL(request,"_self");
quoo
Thanks, that's what I was looking for. Also, though, is there anyways to change the URL (and not necessarily load it) before adding a child to a a page? The child I add get thats variable, but I don't necessarily want to reload the whole page... is it possible to just update the URL and reload a child?
joshholat
I think that might be best posed as another question, as I don't really see what adding a child has to do with a URL request?
quoo
A: 

Hi Guy's

I was wondering if someone could help, as i have a little spin on this?

What if the "myNameVar" needed to be dynamic? (i.e josh, steve, etc)

How could i load a dynamic entry into myNameVar using flex?

Forgive me i am a newby with as and flex, but your help would be much appreciated.

Regards

Steve