Posted By

Activetuts on 01/13/11


Tagged


Versions (?)

Who likes this?

16 people have marked this snippet as a favorite

chus
gandreini
elbjoern
EderChrono
toxin20
alsodenn
ichnoweb
kure69
AndrewPotter
shuchii
JaaQ
im3der
souellette
elderhsouza
coutlasssupreme
flashdeveloper


Get URL of the Page Where SWF is Embedded


 / Published in: ActionScript 3
 

URL: http://enva.to/e4ig6z

To get the complete URL as it appears in your web browser's address bar we use AS3's ExternalInterface class. Without going into too much detail, know that in this example we use ExternalInterface to access the DOM (Document Object Model) of the HTML page which contains our Flash. A downside of ExternalInterface is that the SWF must be embedded in the HTML page with the "allowscriptaccess" parameter set to either "sameDomain" or "always". This is OK when you control the embedding of a SWF but unfortunately cannot be relied upon if the SWF may be run on third party websites. Don’t forget to add import flash.external.ExternalInterface at the top of your document.

  1. function get currentURL():String
  2. {
  3. var url:String;
  4. if (ExternalInterface.available) {
  5. return ExternalInterface.call("window.location.href");
  6. }
  7. return url;
  8. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: tom_press-agrum on January 20, 2011

ExternalInterface return an undefined value.

You must add the "function" string to get the value : "function(){return window.location.href;}"

You need to login to post a comment.