Log in

View Full Version : Stopping a .swf by clicking anywhere outside of movie



europe451
04-20-2010, 03:36 AM
Hello,

So I am having a problem on my HTML page. I have a flash (.swf) video player that is controlled by AS 3 and the problem I am having is that I need the video player to stop whatever its playing when the user clicks anywhere on the screen.

If there are any other details that are needed please let me know.

Thanks in advance for any help

BLiZZaRD
04-20-2010, 06:17 PM
In AS3 it is pretty easy. You will want to relace the traces here with your code, but it would be like this:



function main():void
{
stage.addEventListener(Event.DEACTIVATE, windowNotActive);
stage.addEventListener(Event.ACTIVATE, windowActive);
}
main();

function windowNotActive(e:Event):void
{
trace("NOT ACTIVE");
}

function windowActive(e:Event):void
{
trace("ACTIVE");
}


When the Flash areas has the focus then you will see "ACTIVE" in the output window, when you click outside the output window will say "NOT ACTIVE". Just put the functions in your script where you need them, and add a pause effect into the windowNotActive function.

europe451
04-20-2010, 07:35 PM
Thanks for the reply, quick question though, when you say "replace the traces with your code" does that mean replaces the traces with the file name of the code? I am generally a designer and don't know much about coding but if that isn't the case, what code should I put there?

BLiZZaRD
04-20-2010, 07:44 PM
Well, you want to stop the movie when it doesn't have focus.

So your focus event will be something like:



function main():void
{
stage.addEventListener(Event.DEACTIVATE, windowNotActive);
stage.addEventListener(Event.ACTIVATE, windowActive);
}
main();

function windowNotActive(e:Event):void
{
stop();
}

function windowActive(e:Event):void
{
play();
}