Detecting URL?

Hi,

I was wondering whether some Actionscript exists that can detect what URL its SWF is in, and jump to a frame within the SWF accordingly?

For instance if menu.swf detects that it is embedded within home.html,it goes to Frame 1. Or if it detects it’s embedded within services.html it goes to Frame 2, etc.

If this is a ridiculous question, please excuse my ignorance.:hat:

Just wondering. It would be useful.

Thanks!

this.createEmptyMovieClip(“image_mc”, 1);

var mclListener:Object = new Object();

mclListener.onLoadInit = function(target_mc:MovieClip)
{
trace("_url: "+target_mc._url);
};
var image_mcl:MovieClipLoader = new MovieClipLoader();

image_mcl.addListener(mclListener);

image_mcl.loadClip(“http://www.macromedia.com/images/shared/product_boxes/112x112/box_studio_112x112.jpg”, image_mc);

// use can load jpg,swf orpng here and get its url using _url property of movieclip
that it is loaded into

[Courtesy: Adobe]

I may be wrong… but I don’t think this is what I’m looking for.

[QUOTE=GGMcGee;2349299]I was wondering whether some Actionscript exists that can detect what URL its SWF is in[/QUOTE]

Here are some links with some thoughts:

likewise something like this should work:

var jsFunc:String = "function() { return window.location.toString(); }";
returnLoc(flash.external.ExternalInterface.call(jsFunc));
function returnLoc(url:Object):Void {
	location_txt.text = url;
}

Then set up some conditions based on what is returned. Hopefully one of those gets you going. :thumb:

Use flashvars. For example, edit each HTML page like so:

  1. Within the OBJECT tag, place PARAM NAME=movie VALUE=“menu.swf?HTMLPage=home” for the home.html page and PARAM NAME=movie VALUE=“menu.swf?HTMLPage=services” for the services.html page.

  2. Do the same with the EMBED tag, e.g. EMBED src=“menu.swf?HTMLPage=home” and EMBED src=“menu.swf?HTMLPage=services”

  3. If you’re using SWFObject to embed your SWF file, use the following code; so.addVariable(“HTMLPage”, “home”); and so.addVariable(“HTMLPage”, “services”); for each respective page.

  4. Repeat the above steps for every HTML page that you want to detect.

  5. In the root timeline of your menu.fla you can use an if or switch/case statement, e.g.

switch (HTMLPage) {
case "home" :
	targetFrame = 10;
	break;
case "services" :
	targetFrame = 20;
	break;
// repeat for each page you want to detect, e.g.
case "contact" :
	targetFrame = 30;
	break;
default :
	trace("ERROR: HTMLPage has no corresponding flashvar");
	targetFrame = 99;
	break;
}
gotoAndStop(targetFrame);

[QUOTE=glosrfc;2349713]Use flashvars[/QUOTE]

D’oh, good call glosrfc :wink:

Thanks for the help :smiley: