Random Dynamic Active Slideshow

Have you tried Active Slideshow and loved what it does, but wanted more. I have taken the Active Slideshow Extension and placed code to allow a dynamically generated random picture to be displayed in side of it. The trick is writing the xml document the slideshow will get its data from.

Have you tried Active Slideshow and loved what it does, but wanted more. I have taken the Active Slideshow Extension and placed code to allow a dynamically generated random picture to be displayed in side of it. The trick is writing the xml document the slideshow will get its data from.

What You Need and Languages


Dreamweaver

SQL databasae

ASP VB

Active Slideshow extension from DMXZONE.com

Step One


  1. First create a new files named gallery.asp and paste the code below into that blank document.
  2. Change the totalpics (first code block) to your desired number of random pictures to return.
  3. Set your active slideshow settings manually (sixth comment down)
  4. Change the recordset to work with your database ( randomPicRS )
  5. Change your relative location to your picture files and picture field
  6. Choose where you want the xml saved to. Look for comment save xml
  7. Make sure the FlashVars is set to the same location for where you saved the xml document. Mine is .. /files/ gallery.xml . This is in two spots, make sure you change both!
  8. In the page where you want the slideshow to be located put an include file to the gallery.asp . Make sure you have your connection string at the top of this page!

Other Tips

Make sure the images in this directory are sized accordingly. You can use the Pure Upload ASP to get images into this directory and Smart Image Processor to make the images the correct size.

CODE


<%
‘Select how many picture you want to return to be displayed
DIM totalpics , currentpic
totalpics = 10
currentpic = 0
%>

<%
'Create XMLDOM Object

‘This is where the XML Document starts to be created
Dim xmldoc , galleryxml
Set xmldoc = Server.CreateObject ( " Microsoft.XMLDOM ")

‘ galleryxml is a blank holder for what will be our content of our xml document
galleryxml = " "

' Build the XML document
galleryxml = "<?xml version='1.0' encoding='UTF-8'?>"

‘ you will need to change Active Slideshow attributes manually here
galleryxml = galleryxml & "<slideshow effecttime ='10' transtime ='2' music='' volume='50' repeat='true' streaming='true' loopslideshow ='true' onclick ='' onclicktarget ='_self' doafter ='' doaftertarget ='_self'>"

'Loop through the recordset that will get each random picture from the database

DO WHILE currentpic < totalpics

‘The recordset where our images are stored, change these settings to yours.

Dim randomPicRS
Dim randomPicRS_numRows

Set randomPicRS = Server.CreateObject ( " ADODB.Recordset ")
randomPicRS.ActiveConnection = MM_Conn_STRING
randomPicRS.Source = "SELECT categoryName , picture FROM dbo.PictureCats "
randomPicRS.CursorType = 0
randomPicRS.CursorLocation = 2
randomPicRS.LockType = 1

randomPicRS.Open ()
randomPicRS_numRows = 0

‘This is where the random picture is generated

DIM thepicture
Dim rrSource_randomPicRS , rrRecCount_randomPicRS , re _randomPicRS

Set re_randomPicRS = New regexp
re_randomPicRS.Pattern = "SELECT (.*) FROM "
re_randomPicRS.Global = False
re_randomPicRS.IgnoreCase = True

rrSource_randomPicRS ="Select Count( *) as RecCount From " & re_randomPicRS.Replace ( randomPicRS.Source ,"")
rrRecCount_randomPicRS = CInt ( randomPicRS.ActiveConnection.Execute ( rrSource_randomPicRS )(" RecCount "))
Set rrSource_randomPicRS = Nothing
Set re_randomPicRS = Nothing
randomPicRS.MoveFirst
Randomize

randomPicRS.Move ( Int (( rrRecCount_randomPicRS * Rnd ) + 0))

‘This is the relative location to where your pictures are stored.
thepicture = "../files/cat/"
thepicture = thepicture & ( randomPicRS.Fields.Item ("picture").Value)

galleryxml = galleryxml & "<slide filename='" & thepicture & "' />"

randomPicRS.MoveFirst ' RandomRecord_tail randomPicRS

randomPicRS.Close ()
Set randomPicRS = Nothing

currentpic = currentpic + 1

LOOP

galleryxml = galleryxml & "</slideshow>"

'Save the XML doc, change this to where you want to xml saved, must be write enabled)
xmldoc.loadXML galleryxml
xmldoc.save server.mappath ( "../files/ gallery.xml ")
%>


<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="100%" height="150" id="Gallery" align="middle">
<param name="FlashVars" value="xmlFile=../files/gallery.xml&progressColor=0x000000" />
<param name="movie" value="slideshow.swf" />
<param name="quality" value="best" />
<param name="scale" value="scale" />
<param name="bgcolor" value="#FFFFFF" />
<embed src="slideshow.swf" id="Gallery" quality="best" flashvars="xmlFile=../files/gallery.xml&progressColor=0x000000" scale="scale" bgcolor="#FFFFFF" type="application/x-shockwave-flash" width="100%" height="150" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>

Comments

For Access

September 29, 2005 by Jeremy Conn
Any idea what would be different for using with an Access DB? Great article...

Access

September 29, 2005 by James Hanifen
You will need to change the recordset that retrieves your pictures from the database. Below that code is the code for the random picture, I am not sure if this will work with access.

Limit

October 27, 2005 by Auz Clement
Is there a limit for the amount of pics to be returned in the recordset.  I am aksing because my page was working fine until I started uploading more and more pics.  Now for some reason the XML file is written, but only contains one blank line.  Any suggestions?

RE: Limit

October 27, 2005 by Auz Clement
Nevermind... I think I found the error.  Make sure none of your pics contain the characters "&" or "." :)
See all 5 Comments

You must me logged in to write a comment.