Reputation: 107
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>
Upvotes: 0
Views: 833
Reputation: 2228
function callToActionscript(str)
{
getFlashMovie("nameOfFlashMovie").sendToActionscript(str);
}
window.action = callToActionscript('left');
Hope you are expecting this.
Upvotes: 1
Reputation: 15570
Your javascript isn't failing, but you are passing two strings into the callToActionscript
function, and it expects only one. The result of this is that you are sending the string "asjs" into Flash, and since your callFromJavascript
function expects only "left" or "right", it does nothing.
Try it with just the value you want to pass:
<script type="text/javascript">
callToActionscript('left');
</script>
Also, you don't need the language="javascript"
in your script tag. You've already given the language as part of the mime type.
Upvotes: 1