Community Documentation

Lightbox2 - How to to open a lightbox from a Flash movie

Last updated December 30, 2008. Created by stella on December 30, 2008.
Log in to edit this page.

Taken from #324365: Open Lightbox2 from Flash movie - credit goes to nathan573.

To open a lightbox from a Flash movie you basically have to hit a javascript function that clicks an invisible lightbox link.

First, put this on your page somewhere:

<script type="text/javascript">
function openLightbox() {
fireEvent(document.getElementById("idOfYourLink"),'click');
}

function fireEvent(obj,evt){
var fireOnThis = obj;
if( document.createEvent ) {
var evObj = document.createEvent('MouseEvents');
evObj.initEvent( evt, true, false );
fireOnThis.dispatchEvent(evObj);
} else if( document.createEventObject ) {
fireOnThis.fireEvent('on'+evt);
}
}
</script>

Then create your HREF link to lightbox, like you normally would, although make it empty:

<a href="/path/to/pic/or/page" rel="lightframe[overlayWindowName|width:920px; height:540px; scrolling: no;]" id="idOfYourLink"></a>

Then call the following from your Flash button:

  getURL("javascript:openLightbox();", "_self");

Put the empty link somewhere it won't get in the way - keep it close to the SCRIPT for ease-of-maintenance.

Advantages are that you don't have to code the link destination into the Flash movie, it's just a generic trigger.

Disadvantages are that this is a bit kludgy and you have have add new js, html and Flash code for each different flash button/lightbox. I'd be curious to know if there is a better way of doing this, but this is what I came up with after a couple hours of Googling.

Comments

jQuery

If your using lightbox 2 your using jQuery, why not use it. You can also write dynamic links from your flash:

// ACTIONSCRIPT

ExternalInterface.call("createLightbox", "124", "lightboxCollection");
ExternalInterface.call("clickLink", "124);

// JAVASCRIPT

Create a link:

function createLightBox(nid, boxName)
{
$("#myDivId").append(' ');
Lightbox.initList();
}

Click a link

function clickLink(nid)
{
$("#dynamicLink"+nid).click();
}

IMPORTANT You need to remember to re-init the lightbox on dynamicly created links.

Lightbox.initList();

Cheers

set flash value and get value in javascript

Flash code

on (release) {
getURL("javascript:launchwin('/sites/default/files/videos/1.FLV' , 'newwindow' , 'height=150,width=300')");
}

Javascript :

function launchwin(winurl,winname,winfeatures)
{
document.getElementById("selector").setAttribute("href",winurl);

}

<a id="selector" title="" rel="lightvideo[width:480px; height:120px;]" > </a>

Thanks
Mayur Pimple
www.mayurpimple.com

Where do I locate the file lightBoxInit.js?

Where do I locate the file lightBoxInit.js? I don't see it in either module.Thanks, maci

macmkt

Page status

No known problems

Log in to edit this page

About this page

Drupal version
Drupal 5.x, Drupal 6.x

Site Building Guide

Drupal’s online documentation is © 2000-2013 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.