0

I'm having trouble calling a function through the use of ExternalInterface.

First off, here's the HTML/JS side:

<p align="right">
<object type="application/x-shockwave-flash" data="camera.swf" 
width="200" height="200" align="right" id="camSWF">
<param name="movie" value="camera.swf" align="right" />
<param name="allowScriptAccess" value="always" />
</object></p>
<script type="text/javascript">
var flashObj = document.getElementById('camSWF');
document.onmousemove = setMouseXY;
function setMouseXY(e) {
    var x = e.pageX;
    var y = e.pageY;
    flashObj.rotateCam(x, y, $(document).width(), $(document).height());
}
</script>

And secondly, here is the ActionScript 2 code:

ExternalInterface.addCallback('setMouseXY', null, rotateCam);
function rotateCam(mouseX, mouseY, docWidth, docHeight)
{
    // DO STUFF
}

As far as I can see, everything should work, but obviously I'm missing something.

Whenever the mouse event fires on the HTML page, I get this error in Firebug:

flashObj.rotateCam is not a function: 
flashObj.rotateCam(x, y, $(document).width(), $(document).height());

I'm quite stuck. Perhaps it's some security thing?

1 Answer 1

2
ExternalInterface.addCallback('setMouseXY', null, rotateCam);

This statement adds "rotateCam" as the callback function for "setMouseXY". So "setMouseXY" is the function that has to be called from javascript.

function setMouseXY(e) {
    var x = e.pageX;
   var y = e.pageY;
   flashObj.setMouseXY(x, y, $(document).width(), $(document).height());
}
Sign up to request clarification or add additional context in comments.

2 Comments

Or in actionscript you can use ExternalInterface.addCallback('rotateCam', null, rotateCam); to work with the current javascript code.
Hm, thanks for that. I probably should read code a little more carefully next time

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.