Thursday, December 11, 2008

Dynamically changing the browser title in ActionScript

Many of you have probably set the Application.pageTitle property. But as the documentation says, that property can only be set in MXML. So how do you change it dynamically in ActionScript?

One way that I found is to use the ExternalInterface class and use JavaScript like this:
ExternalInterface.call("eval(window.document.title = 'New Title')");

Obviously you'd want to escape any single quotes in the new title.

One other way I found to do this is using the BrowserManager(if you have it enabled):
var browser:IBrowserManager = BrowserManager.getInstance();
browser.init("""New Title");
// or this way:
browser.setTitle("New Title");

Hope this helps!

No comments: