views:

40

answers:

2

I need to grab values from the querystring and inject them into a getURL(""); snippet that's in the on (release) {} for a button.

So if the URL that contains the embedded swf is

http://domain.com/player.html?returndomain=otherdomain.com

I'd like to get that otherdomain.com and inject it. Something like

var returnUrl = "";
// do magic querystring getting
getURL(returnUrl);

*Edit: I need to snag the querystring because I don't have access to the embed code. It's being rendered by a third party (Articulate) and loaded into a frame. I do have access to the code that renders the frame html, which is why I figured query string would be the best route, and one button that's used in the presentation.

Note, I live in C# land, not ActionScript land so I most likely butchered the syntax. I just need to get this button working as a one off and I'll probably never deal with it again.

BTW, I've seen the abdulqabiz QueryString object that's floating around out there but it kind of seems like overkill, like there should be something baked into the framework for this. I also lack the knowledge of how to incorporate this into my little button on (release) {} event

A: 

There are a variety of options open to you but I guess the simplest way to do it is to use a FlashVar. You can define Strings as FlashVars in your HTML Embed code, and then you will have access to them in you ActionScript.

Are you using AS2 or AS3?

Either way, just google "How to use FlashVars" and you should be set. Let me know if any part of that is confusing or frustrating, I can help you step through it.

Myk
I forgot to add the constraint that I'm dealing with. I can't touch the embed code. I only have control of this button. I'll edit the question.
Dzejms
I was also going to suggest outsourcing the work to JavaScript and then calling your JS method with ExternalInterface - is that an option, or are your hands tied there, too?The final way you can get URL information is to use "this.loaderInfo.URL" - but I can never remember if that returns the URL of the SWF or the URL of the containing HTML...
Myk
this.loaderInfo.URL looks promising. I'll give it a shot tomorrow. Thanks!
Dzejms
+2  A: 

You can get the query string like this:

import flash.external.ExternalInterface;
var queryString:String = String(ExternalInterface.call("function() { return window.location.search; }"));

For your example above, it would return "?returndomain=otherdomain.com", including the question mark.

this.loaderInfo.url, that is suggested in comments here, is ActionScript 3, in ActionScript 2 it would be this._url, and will give you the URL of the swf file, not the URL of the page.

Lars
Frustrating. So I got everything working with your help. It turns out that the 3rd party authoring tool (Articulate) doesn't support AS 3. They offer a work around with something called a web object, but it doesn't seem to be able to grab the URL. I suspect it's loading some internal Flash web browser or something since it's part of a larger .swf on the page. Do you have an AS 2 friendly version of the code above?
Dzejms
Don't worry about it. Articulate completely wipes out any possibility of grabbing the current URL or query string. I don't know if it doesn't allow ExternalInterface or what, but nothing works. I ended up with a solution that reads from a text file using LoadVars(). Thanks for your help. You answered the question and in a normal situation I'd have been done and on my way hours ago!
Dzejms