Calling Any JS Lightbox from Flash using jQuery



Thanks to Flash’s ExternalInferface’s API you can call JavaScript or receive a callback from JavaScript using Flash. In this example I will show you how to call any Lightbox that is in JavaScript from Flash.
Because almost all prebuilt lightboxes get all the info they need from the <a> anchor we will dynamically create an <a> tag with all the necessary information.
Flash:
import flash.external.ExternalInterface;
button.addEventListener(MouseEvent.CLICK, external, false, 0, true);
function external(evt:MouseEvent):void {
 ExternalInterface.call("external", "lightbox/photos/image1.jpg");
}
JavaScript:
function external(path) { // pass in the correct path to the function so we only need one  for infinite amount of calls from  flash
// if the lightbox does not exist we will make it
 if ($('a#lightbox').length == 0) {
  $("body").append("");
  $('a#lightbox').lightBox();
// if it already exists but the path is different we will set the new path
 } else if ($('a#lightbox').attr("href") != path) {
  $('a#lightbox').attr("href", path);
 }
// now we will simulate the click here.
 $('a#lightbox').trigger("click");
}
View demo Here
Share and Enjoy:
  • Print
  • Digg
  • StumbleUpon
  • Slashdot
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Share/Bookmark
  1. #1 by Andrew DiFiore on December 8, 2009 - 4:46 pm

    Thanks but your demo link yields a Not Found message.

(will not be published)