Flash question
- Started
- Last post
- 3 Responses
- nosaj
Any suggestions as to how I could check if a browser window is active and let flash know?
I'm wokring on a site that has some ambient sound effects but they only want them to be audible when the window is active.
- threadpost0
I tired to do something similar once, but found it wouldn't work unless it's running in projector mode.
This was a few versions back however, AS3 might have more support for it with all the new JS support.
Post it up if you get it to work.
- liamegan0
It's not going to be entirely foolproof - for example, it will probably fail in opera on discreet window blurring events - but you're going to need to use javascript to detect the window blur and focus and pass a call back to flash. You can do this like so:
// FLASH CODE
import flash.external.ExternalInterface...
function getFocus(str:String):Void
{received_ti.text = "From JavaScript: " + str;
}
ExternalInterface.addCallback("s... this, getTextFromJavaScript);
function clickSend(eventObj:Object):Void {
var jsArgument:String = sending_ti.text;
var result:Object = ExternalInterface.call("getTextF... jsArgument);
received_ti.text = "Returned: " + result;
}
send_button.addEventListener("cl... clickSend);I'm assuming the use of AS2 here (but I can provide examples of AS3 usage too)
- liamegan0
Sorry, that posted before I'd finished typing:
// FLASH CODE
import flash.external.ExternalInterface...
function getFocus(str:String):Void
{
// your code here based on "true"/"false" response
}// JAVASCRIPT CODE
function getFlashMovie(movieName)
{
var isIE = navigator.appName.indexOf("Micro... != -1;
return (isIE) ? window[movieName] : document[movieName];
}
window.onblur = function()
{
getFlashMovie("yourFlashMovieID...
};
window.onfocus = function()
{
getFlashMovie("yourFlashMovieID...
};