Saturday, November 24, 2012

Getting the window title in AS3

In AS3, you can easily access the name of the HTML page that the .swf is embedded in. To do this, you can use ExternalInterface. First, import the ExternalInterface library.

import flash.external.ExternalInterface;

Next, call the window location from JavaScript using the call function of ExternalInterface.

flash.external.ExternalInterface.call("window.location.href.toString");

This should work for most browsers; however, there have been reported problems using this method. If you experience difficulties with your browser, try wrapping the call in a JavaScript function.

flash.external.ExternalInterface.call("function(){ return window.location.href.toString();}")

In addition, you may want to find the path of the .swf file. Using the following code will get the path of the .swf:

var swfLocation = this.location.href;

One final note, the ExternalInterface calls only work when JavaScript is enabled on the page, so if it does not work, this may be the issue.

Happy Coding,
kieblera5

No comments:

Post a Comment