Flash から Lightbox を起動する方法

ヨロPICO!をブログに設置してみたところ、Lightbox の方に不具合が出た。どうやら Lightboxprototype.js を使用)と Thickbox(jQuery を使用)は共存できないらしい。つまり prototype.jsjQuery のコンフリクト。

そこで、Lightbox 版のヨロPICO!をつくることにした。

Flash から Lightbox を呼び出すのは Thickbox の場合より多少面倒。Javascript でエレメントを生成してやり、そのエレメントに対して SWF から Lightbox リンクを張った上で起動してやる。とりあえず以下を参考に。

First, you'll need to insert the following javascript function between the head tags of your document.

<script type="text/javascript">
   function LightboxDelegate(url,caption) {
   var objLink = document.createElement('a');
   objLink.setAttribute('href',url);
   objLink.setAttribute('rel','lightbox');
   objLink.setAttribute('title',caption);
   Lightbox.prototype.start(objLink);
}
</script>

Now if you've followed my previous post, regarding calling javascript functions via Flash this next step is a snap. You're going to be using the getURL command in Flash, to call the javascript function that you've just pasted into your document above. So, somewhere in your Flash movie you're going to have something similar to the following:

getURL("javascript:LightboxDelegate('images/green_enl.jpg','Green Wallpaper')");

This is some sample code taken from the example Flash video above. You'll notice that we're calling our LightboxDelegate function, and are specifying two arguments. The first argument is the URL to the image or movie (if using Lightbox++) in which you wish to display. The second argument is simply a caption, in which you can set to whatever you would like.

Next you will need to embed your Flash movie into your document that has your Lightbox script installed. In your object tags, you're going to need to specify the following params:

<param name="allowscriptaccess" value="samedomain">
<param name="wmode" value="transparent">

In your embed tag you're going to need to insert the following attribute:

wmode="transparent"


さらに、複数の画像をグループとして呼び出したり、静止画ではなくムービーを Lightbox で見せたい場合は、以下の記事が参考になる。

Execute Lightbox Scripts From Flash: Part Deux at Codefidelity


あるいは、単にこのスクリプトをダウンロードして使わせてもらうという手もある。

Bram.us >> flashLightBoxInjector - Start Lightbox from Flash