Select Page

So I am building a little Flex piece, and needed to use the lightbox.js in actionscript 3. I originally found this post: Calling Lightbox.js from Flash (although it was built using AS2).

Adapt it to AS3 by:

1. Again pushing this Javascript into the tags of the file that will house your SWF


function lightBoxInit(url)
{
var imgLink = document.createElement('a');
imgLink.setAttribute('href', url);
imgLink.setAttribute('rel','lightbox');
Lightbox.prototype.start(imgLink);
}

2. In your actionscript you would add this (in my case, Flex):


private function runLightbox(eventObject:MouseEvent):void
{
var lightBoxCommand:String = "lightBoxInit('images/" + this.image + ".jpg');";
var url:URLRequest = new URLRequest("javascript:" + lightBoxCommand);
navigateToURL(url, "_self");
}

PS. make sure your swf param’s allowScriptAccess “always”.

werd.