0

I have some actionscript that plays a movie clip. When the movie clip is over I want Javascript to remove the Flash object from the page. I can't seem to get it working.

When I test the actionscript in Flash I don't get any compilation errors, and my Traces all execute when I expect. I also don't get any javascript errors thought the RemoveFlash() function never gets called.

Here's my ActionScript3:

import fl.video.*;
import flash.external.ExternalInterface;

MyPlayer.addEventListener(VideoEvent.COMPLETE, completePlay);

MyButton.addEventListener(MouseEvent.MOUSE_DOWN, interruptPlay);

function completePlay(e:VideoEvent):void
{
    trace("video completed");
    ExternalInterface.call("RemoveFlash");
}

function interruptPlay(e:MouseEvent):void
{
    trace("video interrupted");
    MyPlayer.stop();
    ExternalInterface.call("RemoveFlash");
}

And here is my JS:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <script language="javascript" type="text/javascript" src="/Scripts/jquery-1.5.min.js"></script>
    <script type="text/javascript" src="/Scripts/swfobject2.js"></script>

    <script type="text/javascript">
        $(document).ready(function(){

            // Remove GreenPlayer
            function RemoveFlash()
            {
                alert("remove");
                $("#GreenPlayer").remove();
            }

            // add greenscreen swf
            var flashvars = {};
            flashvars.AllowScriptAccess="always";

                    var params = {};
            params.wmode = "transparent";
            params.AllowScriptAccess = "always";

            swfobject.embedSWF("/swf/GreenPlayer2.swf", "GreenPlayer", "200", "400", "8.0.0", '', flashvars, params);

        });
    </script>
</head>
<body>
        <div id="GreenPlayer">asd</div>
</body>
</html>

Any Thoughts?

2
  • If you remove $(document).ready(function(){});, what happens? Commented Feb 28, 2011 at 19:12
  • Then the swfobject won't function correctly because it will try to write the flash object into a div that doen't exist yet. Commented Feb 28, 2011 at 19:17

2 Answers 2

1

Maybe the RemoveFlash() function is out of the scope of the swf because you have it in an anonymous function. Try moving the RemoveFlash() function into the global scope (outside of $(document).ready) and see if it helps.

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

2 Comments

Ummm... I see. that is interesting and it brings up a slight problem. I can't define the function until after the document is done loading because I need to interact with the DOM.
Yes you can define the function before the DOM is loaded. Just don't call it until the DOM is ready.
1

Your RemoveFlash function is local to your ready handler and flash is trying to call a global function called RemoveFlash(). Move it outside of the load handler and it'll work...

<script type="text/javascript">
    function RemoveFlash() {
       $("#GreenPlayer").remove();
    }      

    $(document).ready(function(){
        // add greenscreen swf
        var flashvars = {AllowScriptAccess: "always"};
        var params = {
           wmode: "transparent",
           AllowScriptAccess: "always"
        };
        swfobject.embedSWF("/swf/GreenPlayer2.swf", "GreenPlayer", "200", "400", "8.0.0", '', flashvars, params);

    });
</script>

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.