Werd.

Write Code And Carry A Big Stick

  • Blog My rumblings & other stuff
  • About Developer / Designer
  • 21st Paradigm Non-Profit Organization
  • Portfolio Some of my work

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

Posted Under Actionscript3 Flash Flex News

7 Comments

  1. michako
    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”);
    }

  2. Zara
    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…..

  3. Anthony
    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/

  4. Campbell
    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?

  5. Campbell
    September 16, 2008

    sorry * “…used in the Html version of lightbox and also….”

  6. Bill Triplett
    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);
    }

  7. admin
    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

* = Required

    • Posts
    • Twitter
    • Flickr
     

    Small Turtle Po...

    Uncategorized

     

    Backyard Farmin...

    Other

     

    Redlight: A mov...

    News

    Flex 4 Ant Tasks and I don't seem to be getting a long right now.

    follow me on
    twitter

    IMAG0102IMAG0095IMAG0098IMAG0100IMAG0090IMAG0087IMAG0104IMAG0070IMAG0071IMAG0075
  • Categories

    • Actionscript3
    • AJAX
    • Coldfusion
    • Design
    • Development
    • Flash
    • Flex
    • News
    • Other
    • Personal
    • PHP
    • Ranting
    • Uncategorized
  • Archives

    • 2010
      • February
      • April
      • May
      • June
      • July
    • 2009
      • January
      • February
      • March
      • May
      • June
      • July
      • August
      • October
      • November
      • December
    • 2008
      • January
      • February
      • March
      • April
      • May
      • June
      • July
      • August
      • September
      • October
      • November
    • 2007
      • January
      • February
      • March
      • April
      • June
      • July
      • August
      • September
      • October
      • November
      • December
    • 2006
      • July
      • August
      • September
      • October
      • November
      • December

This site is using the Handgloves WordPress Theme
Designed & Developed by George Wiscombe

Subscribe via RSS