
Need to load a random album in a gallery at startup? Here's how you can do it.
In your FLA, make sure your instance of SlideShowPro on the stage has an instance name. For this example, we'll name it "my_ssp". Then in an empty keyframe directly above or below the same numerical keyframe SlideShowPro is in, open the Actions panel. If you are using the ActionScript 2 version of SlideShowPro, enter the following:
listenerObject = new Object();
listenerObject.onGalleryData = function(eventObject):Void {
var ids:Array = new Array();
var gallery:Array = eventObject.data;
for (var i=0;i<gallery.length;i++) {
ids.push(gallery[i][0].id.toString());
}
var ranNum = Math.floor(Math.random() * gallery.length);
_root.my_ssp.loadAlbum(ids[ranNum]);
}
my_ssp.addEventListener("onGalleryData", listenerObject);
If using the ActionScript 3 version...
import net.slideshowpro.slideshowpro.*;
function onGalleryData(event:SSPDataEvent):void {
var ids:Array = new Array();
var gallery = event.data;
for (var i=0;i<gallery.length;i++) {
if (gallery[i][0].id) {
ids.push(gallery[i][0].id);
}
}
var ranNum = Math.floor(Math.random() * gallery.length);
my_ssp.loadAlbum(ids[ranNum],1);
}
my_ssp.addEventListener(SSPDataEvent.GALLERY_DATA, onGalleryData);
Here's how it works. We listen for SlideShowPro to broadcast gallery data. When it does, it creates an array to store album IDs, another array to store the gallery data, then walks through the gallery pulling out the ID of each album and storing it. Then it generates a random number between 0 and the total length of the gallery, and calls setStartAlbum with the ID of the album it should load.
Note: make sure that each album in your gallery has an ID assigned to it, like so...
<album id="nature" ...>
Now each time your SWF loads, a random album will be chosen to start with.

