May 2, 2008
Posted by admin
Actionscript 3 and LightBox js
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.










7 Comments
June 18, 2008
Hey!
Nice one.Haven’t tested yet though!!
I ‘ll use ExternalInterface instead.
private function runLightbox(eventObject:MouseEvent):void
{
ExternalInterface.call(“lightBoxInit”,”http://www.yoursite.com/image.jpg”);
}
June 23, 2008
hey …ive been lookin for a post wlike yours for a bit but could you expand on your example a bit? im getting a compiling error in flash
(1013: The private attribute may be used only on class property definitions.) if you could please give a bit of help id be greatful…i just have a few buttons on the screen that on click will call other content and load it in the light box…..
June 23, 2008
Check out this link on your error, I can’t really give you an answer without seeing code, but should be fairly simple, all AS3 is the same, but remember as I am using Flex.
http://curtismorley.com/2007/11/19/flex-2-flash-cs3-actionscript-error-1013/
September 16, 2008
Hey i’m building a self promotion website and it’s flash. I want to use the lightbox with in my flash web page but its proving to be quite difficult.
Is there a way to call upon all the appropriate javascript files used in an html version and some how link the images so I can take out the middle-man of html? What i’m trying to achieve is a lightbox with no Html…
Can you please help me?
September 16, 2008
sorry * “…used in the Html version of lightbox and also….”
May 25, 2010
I’m also having trouble working with lightbox and flash as 3.
This works to direct to an image file but can’t seem to figure out how to include the lightbox and have it work. I’ve looked at so many web forums I’m more confused than when I started.
import flash.events.MouseEvent;
var reqprint1:URLRequest = new URLRequest(“../images/homeowner.jpg”);
btn2sub1.addEventListener(MouseEvent.CLICK,b21Click);
function b21Click(event:MouseEvent):void{
navigateToURL(reqprint1);
}
May 25, 2010
Hey Bill, not sure what you mean exactly, but if you are trying to apply lightbox to that image your code would looks something like this:
var lightBoxCommand:String = “lightBoxInit(‘../images/homeowner.jpg’);”;
var reqprint1:URLRequest = new URLRequest(“javascript:” + lightBoxCommand);
btn2sub1.addEventListener(MouseEvent.CLICK,b21Click);
function b21Click(event:MouseEvent):void{
navigateToURL(reqprint1, “_self”);
make sure you have the Javascript in place too.
Leave a comment