Scriptplayground

 Print Page | Close Window

Call Javascript in Flash

Run Javascript in Flash without the need of extra code in your HTML file.

Have you ever needed to test some variables or call a function from in Flash? Well here is the answer.

function runJS(script:String):Void {
	getURL("javascript:" +  script + "");
}

var js = "var doc = document.URL; alert(doc);";
runJS(js);

That example block of code is basically a function that handles a call to "getURL" which actually executes the Javascript. This example displays in a message box the current URL of a document. Which of course will only work if you are previewing the SWF in a web page or Flash will attempt to open your default web browser.

There isn't a lot to this idea, just makes it a little easier to run Javascript in Flash.


Find this article at:
http://scriptplayground.com/tutorials/as/Call-Javascript-in-Flash/