Flash ActionScript Grab Query String Value

2019-06-05 20:05发布

问题:

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

回答1:

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.



回答2:

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.