Calling jQuery from inside Flash??
Hey All,
So I've got a jQuery fade effect working fine. Script is all good and
it works great if called when clicking a link. But I want to call the
script from inside a Flash movie instead. I've got that Actionscript
working fine as well - it calls the function I want (tested with
alerts) so that's fine too.
At first, the Flash call wasn't working, but it seems to be
functioning now that I removed the "$(document).ready(function() {}"
wrapper.
So, now for the main issue...
For some reason, anything inside my javascript that requires getting
values from the DOM or running a jQuery effect like fades, etc,
doesn't work? They return undefined values or just don't run?
Here is my javascript (below). The basic alerts all work fine, so
obviously the script is running. But what leads me to believe it's
some issue with focus or the DOM is that the one alert which returns
"undefined" is the alert after the Firefox check (isFF) function.
That one, which simply checks for a "navigator.userAgent" value (and
works fine when called from a link so I know the function works)
returns undefined when the chain of functions is started from a Flash
call.
Is it possible the Flash movie still has the focus rather than the
window, so the "DOM" values are all undefined or something? Any help
would be great... this is making me nuts!
- - - - - - - - - -
<script type="text/javascript">
// $(document).ready(function() {
// Embed Flash
var params = {};
params.menu = "false";
params.wmode = "window";
params.allowscriptaccess = "always";
swfobject.embedSWF("myVideo.swf", "video", "300", "270", "9.0.0",
"expressInstall.swf", params);
// End of Embed //
// Build Lightbulb Effect
var isShowing = false;
if (navigator.appName.indexOf("Microsoft") != -1) {
document.getElementById('blackout').style.filter =
"progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true,
sizingMethod=scale src='lightbulb.png')";
} else {
document.getElementById('blackout').style.backgroundImage =
'url(lightbulb.png)';
}
function showLightbox() {
alert("Showing Lightbox. \"isShowing\" = " + isShowing);
adjustLightbox();
var FF_check = isFF();
alert(FF_check);
if (!isShowing) {
if (FF_check) { document.getElementById('blackout').style.display =
"block";
$("#blackout").fadeIn("slow");
isShowing = true;
alert("isShowing is now ... " + isShowing);
} else {
if (FF_check) { document.getElementById('blackout').style.display =
"none";
$("#blackout").fadeOut("slow");
isShowing = false;
alert("isShowing is now ... " + isShowing);
}
};
function getWindowSize() {
alert("Getting Lightbox Size...");
var the_width = document.body.offsetWidth;
var the_height = (typeof window.innerHeight != "undefined") ?
window.innerHeight : (document.documentElement &&
document.documentElement.clientHeight > 0) ?
document.documentElement.clientHeight : document.body.clientHeight;
if (document.getElementById('page').offsetHeight > the_height) {
the_height = document.getElementById('page').offsetHeight;
}
return [the_width, the_height];
};
function adjustLightbox() {
alert("Adjusting Lightbox Size...");
var rra_bounds = getWindowSize();
document.getElementById('blackout').style.width = rra_bounds[0] +
"px";
document.getElementById('blackout').style.height = rra_bounds[1] +
"px";
};
function isFF() {
alert("Checking FF...");
var userAgent = navigator.userAgent.toLowerCase();
if (userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox')!
=-1) {
return true;
}
}
$(window).bind("resize", function() {
adjustLightbox();
});
// });
</script>