0

None of the similar answered questions fixed my problem, so here it goes. I want to call actionscript 3 function from JavaScript but in FF error console it says that the function I'm calling from JS does not exist. It says functions mover and mout are not defined.

Here is the JS functions in JS file

function getFlashMovieObject(movieName) {
    var isIE = navigator.appName.indexOf("Microsoft") != -1;
    return (isIE) ? window[movieName] : document[movieName];
}
function playF() {
getFlashMovieObject("Button2").mover();
}
function playB() {
getFlashMovieObject("Button2").mout();
}

Here's the code in HTML

<object style="width: 413px; height: 76px;" id="Button2" onMouseOver="playF()"  onMouseOut="playB()">
    <param name="movie" value="homepage/flash/Button2.swf">
    <param value="transparent" name="wmode"/>
    <param value="false" name="loop"/>          
    <embed wmode="transparent" play=false src="homepage/flash/Button2.swf" width="413" height="76" loop="false" swliveconnect="true" name="Button2"></embed>
</object>

And the code in Actionscript 3

ran.stop();
function mover() {
    stopPlayReverse();
this.addEventListener(Event.ENTER_FRAME, playForward, false, 0, true);
}
function mout() {
stopPlayForward();
    this.addEventListener(Event.ENTER_FRAME, playReverse, false, 0, true);
}
function playReverse(e:Event):void {
    if (ran.currentFrame == 1) {
        stopPlayReverse();
    } else {
        ran.prevFrame();
    }
}
function playForward(e:Event):void {
    if (ran.currentFrame == ran.totalFrames) {
    stopPlayForward();
} else {
    ran.nextFrame();
}
}
function stopPlayForward():void {
if (this.hasEventListener(Event.ENTER_FRAME)) {
    ran.removeEventListener(Event.ENTER_FRAME, playForward);
}
}
function stopPlayReverse():void {
    if (this.hasEventListener(Event.ENTER_FRAME)) {
        ran.removeEventListener(Event.ENTER_FRAME, playReverse);
    }
}
ExternalInterface.addCallback("mover", mover);
ExternalInterface.addCallback("mout", mout);

The idea is that I want to control the mouse hovering with javascript and when I hover over the object the movie plays normally but when I hover out then the movie plays backwards. I have the movie clip on one layer and on the other layer I have my actionsrcript code. Can anyone tell me what I'm doing wrong? Thanks

3
  • Is don't use AS3 & Javascript together a valid answer? Best to handle things internally through AS3 & Flash. Commented Jan 25, 2011 at 21:29
  • try changing getFlashMovieObject function body to return document.getElementById(movieName) Commented Jan 25, 2011 at 21:49
  • 1
    I don't accept failure. And I know people got this working. @Tom Tu I tried that, but same errors. Functions are not defined. Commented Jan 25, 2011 at 22:05

1 Answer 1

2

The AS3 and JS codes seem fine, but you need to set the allowScriptAccess flag in the HTML code.

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

1 Comment

Thanks dude. Putting allowScriptAccess to always did the trick.

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.