How to Get the Current Page's URL into Flash

This little trick allows a Flash movie (swf) to find out the URL of the page in which it's embedded. After wondering about this for some time, I finally found a blog post with the solution. Here's the key bit of code:

import flash.external.ExternalInterface;
 
var pageURL:String =
	ExternalInterface.call('window.location.href.toString');

This could be useful if you're using the query string in the URL to keep track of the application's state. However, the solution comes with one caveat: Javascript must be enabled for this to work. The Actionscript 3.0 documentation says that if the window.location.href.toString method doesn't return a value then ExternalInterface.call will return null. Same thing happens when Javascript is disabled.

Here's the original blog post by Abdul Qabiz: How to get URL query-string variables within Flex application

Comments

Alex says, "Is it possible to load a URL"
Alex's picture

Is it possible to load a URL into a flash movie without leaving flash? reason is that I like to use the flash fullscreen to have a real fullscreen for my htm website.

daniel says, "Loading a Page Into Flash"
daniel's picture

Hi Alex,

I realize this is really late but maybe somebody can still benefit from this answer. Flash does a terrible job of rendering entire HTML pages so I definitely wouldn't recommend trying to display a page right in Flash. Unfortunately your best bet is going to be implementing all your content in Flash.

Hope that helps.

Anonymous says, "Thanks for your answer."
Anonymous's picture

Thanks for your answer.

Post new comment

The content of this field is kept private and will not be shown publicly.
If you have a Gravatar account, used to display your avatar.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • You can enable syntax highlighting of source code with the following tags: <code>. Beside the tag style "<foo>" it is also possible to use "[foo]".
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

About

Daniel McLaren

Daniel is a Flash and Flex developer specializing in the art of information visualization.

Latest from SketchyD

Latest Drawing from SketchyD

This is the most recent drawing from my mobile sketch blog, SketchyD.com.

Recent comments