Visit SlideShowPro.net  Community Forums
SlideShowPro Support Wiki
  
Flash component

How to: Load a random album at startup

Need to load a random album in a gallery at startup? Here's how you can do it.

In your FLA, make sure your component instance 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 the component is in, open the Actions panel. If you are using the ActionScript 2, 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 the SlideShowPro Player 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.

Page last modified by tdominey on November 14, 2010, at 09:47 AM
© 2011 SlideShowPro. All Rights Reserved.