# Detecting URL?

**URL:** <https://forum.kirupa.com/t/detecting-url/264425>\
**Category:** flash\
**Created:** [June 26, 2008, 12:56am UTC](https://forum.kirupa.com/t/detecting-url/264425 "2008-06-26T00:56:16Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![GGMcGee](https://avatars.discourse-cdn.com/v4/letter/g/ba8739/32.png) [@GGMcGee](https://forum.kirupa.com/u/GGMcGee)\
**Post date:** [June 26, 2008, 12:56am UTC](https://forum.kirupa.com/t/detecting-url/264425/1 "2008-06-26T00:56:16Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![sparkdemon](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@sparkdemon](https://forum.kirupa.com/u/sparkdemon)\
**Post date:** [June 26, 2008, 4:57am UTC](https://forum.kirupa.com/t/detecting-url/264425/2 "2008-06-26T04:57:26Z")

</div>

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](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]

---

<div class="post-metadata">

**Author:** ![GGMcGee](https://avatars.discourse-cdn.com/v4/letter/g/ba8739/32.png) [@GGMcGee](https://forum.kirupa.com/u/GGMcGee)\
**Post date:** [June 26, 2008, 5:41am UTC](https://forum.kirupa.com/t/detecting-url/264425/3 "2008-06-26T05:41:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![prg9](https://avatars.discourse-cdn.com/v4/letter/p/8dc957/32.png) [@prg9](https://forum.kirupa.com/u/prg9)\
**Post date:** [June 26, 2008, 1:25pm UTC](https://forum.kirupa.com/t/detecting-url/264425/4 "2008-06-26T13:25:51Z")

</div>

[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:

> **[kirupaForum](https://forum.kirupa.com)**
>
> Got a web design/development question or just want to hang out with the most awesome people on the planet? Drop on in!

> **[kirupaForum](https://forum.kirupa.com)**
>
> Got a web design/development question or just want to hang out with the most awesome people on the planet? Drop on in!

likewise something like this should work:

```auto
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:

---

<div class="post-metadata">

**Author:** ![glosrfc](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/glosrfc/32/8334_2.png) [@glosrfc](https://forum.kirupa.com/u/glosrfc)\
**Post date:** [June 26, 2008, 5:08pm UTC](https://forum.kirupa.com/t/detecting-url/264425/5 "2008-06-26T17:08:59Z")

</div>

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.

```auto
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);

```

---

<div class="post-metadata">

**Author:** ![prg9](https://avatars.discourse-cdn.com/v4/letter/p/8dc957/32.png) [@prg9](https://forum.kirupa.com/u/prg9)\
**Post date:** [June 26, 2008, 5:42pm UTC](https://forum.kirupa.com/t/detecting-url/264425/6 "2008-06-26T17:42:16Z")

</div>

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

D’oh, good call glosrfc 😉

---

<div class="post-metadata">

**Author:** ![GGMcGee](https://avatars.discourse-cdn.com/v4/letter/g/ba8739/32.png) [@GGMcGee](https://forum.kirupa.com/u/GGMcGee)\
**Post date:** [July 2, 2008, 3:54am UTC](https://forum.kirupa.com/t/detecting-url/264425/7 "2008-07-02T03:54:32Z")

</div>

Thanks for the help 😃
