I'm using this code to call a actionscript 3 function through javascript
http://www.viget.com/inspire/bi-directional-actionscript-javascript-communication
and I want to call the acrionscript 3 function from a javascript function, but not on a button action.
how do I do that? thanks!
actionscript code:
//call to javascript
ExternalInterface.call("sendToJavaScript");
//call from javascript
ExternalInterface.addCallback("sendToActionscript", callFromJavaScript);
function callFromJavaScript(dir):void
{
if(dir == 'right')
{
var tweenR = new Tween(box, 'x', None.easeNone, box.x, 145, 1, true);
}
if(dir == 'left')
{
var tweenL = new Tween(box, 'x', None.easeNone, box.x, 23, 1, true);
}
}
javascript code:
function getFlashMovie(movieName) {
var isIE = navigator.appName.indexOf("Microsoft") != -1;
return (isIE) ? window[movieName] : document[movieName];
}
function callToActionscript(str)
{
getFlashMovie("nameOfFlashMovie").sendToActionscript(str);
}
html button
<form action="javascript:callToActionscript('asjs', 'left')" id="form1">
<input type="submit" value="<--" />
</form>
I tried calling it like this in the body but it didn't work:
<script type="text/javascript" language="javascript">
callToActionscript('asjs', 'left');
</script>