0

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="&lt;--" />
        </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>  

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1
function callToActionscript(str) 
{
     getFlashMovie("nameOfFlashMovie").sendToActionscript(str);
}
window.action = callToActionscript('left');

Hope you are expecting this.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.