How to create flash gallery using Autoviewer

Tutorials

Today we will continue overviews of available flash galleries. Next gallery is Autoviewer. This is free plugin. We can use mouse and keyboard to navigate between images, also this plugin have play/pause button, autoplay functionality, light weight and of course – cross platform. Hope that you will like this.

One of necessary features of autoviewer is that it able to load xml set of images which you can generate using PHP. So just imagine, that in your script (or maybe some CMS), you will able to generate different galleries based on different params. As example member`s photo galleries of your website.

Here are samples and downloadable package:

Live Demo

[sociallocker]

download in package

[/sociallocker]


Ok, download the example files and lets start coding !


Step 1. HTML

As usual, we start with the HTML. This is source code of our sample:

index.html

01 <link rel="stylesheet" href="css/main.css" type="text/css" />
02 <script src="js/swfobject.js"></script>
03 <div class="example">
04     <h3><a href="#">Autoviewer example</a></h3>
05     <div>
06         <div id="flashcontent">
07             <embed type="application/x-shockwave-flash" src="app/autoviewer.swf" id="viewer" name="viewer" bgcolor="#181818" quality="high" flashvars="xmlURL=feed.php" height="700px" width="100%">
08         </div>
09         <script type="text/javascript">
10             var flashvars = {
11               xmlURL: "feed.php"
12             };
13             var params = {
14               //wmode: "transparent"
15             };
16             var attributes = {};
17             swfobject.embedSWF("app/autoviewer.swf", "viewer", "100%", "700px", "9.0.0","expressInstall.swf", flashvars, params, attributes);
18         </script>
19     </div>
20 </div>

As you can see – initialization is very easy – all through swfobject, where you can set wished params – different colors, sizes, xml data path (for our PHP file) and few more properties. If you want, you can simple set ‘wmode’ to necessary value too (to provide transparency as example).

Step 2. CSS

Here are used CSS file for our demo:

css/main.css

1 body{background:#eee;font-family:VerdanaHelveticaArialsans-serif;margin:0;padding:0}
2 .example{background:#FFF;width:1000px;font-size:80%;border:1px #000 solid;margin:0.5em 10% 0.5em;padding:1em 2em 2em;-moz-border-radius: 3px;-webkit-border-radius: 3px}

Step 3. JS

Here are single JS file:

js/swfobject.js

This is just SWFObject class. Available as a download package.

Step 4. PHP

Here are code of our XML generator (to generate xml-based set of using images):

feed.php

01 <?
02 $sCode '';
03 $sTemplate = <<<XML
04 <image>
05    <url>{fileurl}</url>
06    <caption>{title}</caption>
07    <width>{width}</width>
08    <height>{height}</height>
09 </image>
10 XML;
11 $sFolder 'data_images/';
12 $aUnits array('pic1.jpg' => 'Image 1''pic2.jpg' => 'Image 2''pic3.jpg' => 'Image 3''pic4.jpg' => 'Image 4''pic5.jpg' => 'Image 5''pic6.jpg' => 'Image 6''pic7.jpg' => 'Image 7''pic8.jpg' => 'Image 8''pic9.jpg' => 'Image 9''pic10.jpg' => 'Image 10''pic11.jpg' => 'Image 11''pic12.jpg' => 'Image 12''pic13.jpg' => 'Image 13''pic14.jpg' => 'Image 14''pic15.jpg' => 'Image 15''pic16.jpg' => 'Image 16''pic17.jpg' => 'Image 17''pic18.jpg' => 'Image 18');
13 foreach ($aUnits as $sFileName => $sTitle) {
14     $sFilePath $sFolder $sFileName;
15     list ($iWidth$iHeight$vType$vAttr) = getimagesize($sFilePath);
16     $sCode .= strtr($sTemplatearray('{fileurl}' => $sFilePath'{title}' => $sTitle'{width}' => $iWidth'{height}' => $iHeight));
17 }
18 header ('Content-Type: application/xml; charset=UTF-8');
19 echo <<<EOF
20 <?xml version="1.0" encoding="UTF-8"?>
21 <gallery frameColor="0xFFFFFF" frameWidth="15" imagePadding="20" displayTime="5" enableRightClickOpen="true">
22 {$sCode}
23 </gallery>
24 EOF;
25 ?>

Here I just generate pretty easy XML feed using custom template. You can do this with your images and using different paths to images too. Caption field can allow simple HTML too. So you can left links here or use different fonts for titles.

Step 5. SWF application

app/autoviewer.swf

This is main flash application – Autoviewer. Available as a download package.

Step 6. Images

All our images located in ‘data_images’ folder. Of course, you can use another folder path and name. Just don`t forget to correct feed.php in this case too.


Live Demo

Conclusion

Today I told you how to build new type of flash gallery. Sure that you will happy to use it in your projects. Good luck!

Rate article