Re: Javascript and Flash Hi,
In flash there is a way to call a function written in javascript from flash. We can simply call like this.
getURL("javascript:function_name('parameters seperated by comma')","");
But we can't return values from javascript to flash. To return value use the function below.
var exint = flash.external.ExternalInterface.call("Function Name", Param1, Param2, etc);
The return value should be stored in the "exint" variable.
To call a function written in Flash from Javascript use see this sample below. Codes to be Written in Flash:
import flash.external.*;
var methodName:String = "goHome";
var instance:Object = null;
var method:Function = goToMacromedia;
var wasSuccessful:Boolean = ExternalInterface.addCallback(methodName, instance, method);
var txtField:TextField = this.createTextField("txtField", this.getNextHighestDepth(), 0, 0, 200, 50);
txtField.border = true;
txtField.text = wasSuccessful.toString();
function goToMacromedia() {
txtField.text = "http://www.macromedia.com";
getURL("http://www.macromedia.com", "_self");
} And codes to be in Html page:
<form>
<input type="button" onclick="callExternalInterface()" value="Call ExternalInterface" />
</form>
<script>
function callExternalInterface() {
thisMovie("externalInterfaceExample").goHome();
}
function thisMovie(movieName) {
if (navigator.appName.indexOf("Microsoft") != -1) {
return window[movieName]
}
else {
return document[movieName]
}
}
</script>
Regards
A.Ramesh |