简体   繁体   中英

Is my Flash SWF on screen?

I'd like my flash movie to not play until it's visible on screen and then pause when off screen. Is there a way to capture some event indicating that the swf is rendering or visible or within the visible bounds of the browser window that I can addEventListener to so I'll know when it's within view?

Use Flash's ExternalInterface to call a javascript function that checks to see if the element of off screen. In javascript, use JQuery with the Viewport plugin to figure out if we're off screen. ( http://www.appelsiini.net/projects/viewport ).

I haven't tested the Viewport plugin, but I've talked to people who use it, and it worked out OK for them.

In as3:

var returnValue:int = ExternalInterface.call("jsCheckerFunction");

if(returnValue == 1) // your flash is on-screen.

in javascript:

function jsCheckerFunction()
{
    if($("#flashContent:in-viewport").length > 0) 
        return 1; // flash div visible
    return 0; // returns 0 if the element is offscreen  
}

You could have it call jsCheckerFunction on each frame to see if the status has changed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM