views:

631

answers:

4

I got this flash application where you can click a link while watching a video. It will open a new tab and pause the video. Now when you come back to the flash application it would be nice if the video would start playing again. Is there a way, an event or so to do this ?

+1  A: 

Flash is probably a no-go, but you might have some luck with pure javascript and have that communicate with your Flash Movie. I suggest you play around with the Window's onFocus event.

I've never used it before, so it might not trigger on any/all browsers.

This worked in FF3. It's not valid or good code but it's a stepping stone for you:

<html>
    <head></head>
    <body onFocus="alert('testing');"></body>
</html>

It's also really annoying because clicking okay ok the alert, re-triggers the focus. Control+W will close the tab for you and allow you to break the cycle.

Oli
I've had trouble with onFocus before, it doesn't work 100% of the time. So make sure to design your app in such a way that if you don't get onFocus events, the user can still manually click a button or whatever to make things work again.
davr
A: 

The Flash player send outs activate and deactivate events when the focus enters and leaves the player. You could probably uses these, but they are limited to only when the flash content focus changes, not when the page focus changes.

Take a look here blog.flexaxamples.com to see how to use to the Flash activate and deactivate events.

81bronco
A: 

I think i have solved it like this:

I listen to a mouse_leave event on the stage, because your mouse will leave the stage when in another tab. (or at least, you have to click a tab to get back to the flash, so you always end up outside of the flash). When you left the stage a stageLeave boolean is set to true.

Then I have another event listener, mouse_move that sets the stageLeave boolean to false (when true) and dispatches a custom STAGE_RETURN event.

The only sidenote here is that you'll have to move with the mouse over the stage to make the video play again. But that's something you will do anyway.

Kasper
+2  A: 

A cleaner approach would be to use something along the lines of:
stage.addEventListener( Event.ACTIVATE, playMovie );
stage.addEventListener( Event.DEACTIVATE, pauseMovie );

jpencola