Log in

View Full Version : autoplay pictures in photogallery



crimsonsmeagol
03-16-2009, 04:39 PM
I have a photo gallery and right now the full size pictures load when you click on the thumbnail. I want to change it so that the pictures automatically play without the user having to click on a thumbnail. Any suggestions?

Here is my current code


package actionScriptFiles
{
import flash.display.Shape;
import flash.display.Sprite;
import flash.events.Event;
import flash.filters.DropShadowFilter;
import flash.text.TextFormat;

import fl.controls.Label;
import fl.controls.List;
import fl.controls.RadioButton;
import fl.controls.Slider;
import fl.controls.TileList;
import fl.data.DataProvider;
import fl.managers.StyleManager;

public class ImageViewer extends Sprite
{
private var _imagePane_sp:ScrollPane;
private var _title_lbl:Label;
private var _thumbnails_tl:TileList;
private var _images:ImageData;

public function ImageViewer()
{
init();
}

private function init():void
{
assignComponentReferences();
configureComponents();
assignHandlers();
loadImageData();
}

private function assignComponentReferences():void
{
_imagePane_sp = imagePane_sp;
_title_lbl = title_lbl;
_thumbnails_tl = thumbnails_tl;
}

private function configureComponents():void
{
_thumbnails_tl.columnWidth = 110;
_thumbnails_tl.rowHeight = 50;
_title_lbl.setStyle("textFormat", new TextFormat("Arial", 10));
StyleManager.setComponentStyle(TileList, "cellRenderer", SimpleImageCell);
}


private function assignHandlers():void
{
_thumbnails_tl.addEventListener(Event.CHANGE, onImageSelected);
}

private function loadImageData():void
{
_images = new ImageData();
_images.addEventListener(Event.COMPLETE, onDataLoaded);
_images.load();

}

private function onDataLoaded(event:Event):void
{
_images.removeEventListener(Event.COMPLETE, onDataLoaded);
_thumbnails_tl.dataProvider = new DataProvider(_images.getThumbData());
}

private function onImageSelected(event:Event):void
{
var image:Image = event.target.selectedItem.data as Image;
var index:int = event.target.selectedIndex;
_thumbnails_tl.selectedIndex = index;
_title_lbl.text = image.name + "\n" + image.desc;
_imagePane_sp.source = image.file;
}
}
}

punstc
03-17-2009, 03:48 AM
have you tried creating a timer?

you could create a timer and a variable to hold how many seconds you want to wait befor the next image. add an event listener for the timer and tell it to subtract off your time variable everytime it runs. when it hits zero go the next image in your xml and reset the time. so it starts all over again.

it would look something like this



var timeCount:Number = 30//how many seconds you want to count down;
var myTime:Timer = new Timer(1000)//creates a timer for 1 second;
myTime.start();
myTime.addEventListener(TimerEvent.TIMER, updateTime);

function updateTime(e:TimerEvent) {
timeCount--;
if(timeCount == 0) {
//tell it to go to your next image or run a function to go to the next image;
timeCount = 30//reset the time count so after thirty seconds it all start again.
}

}


if you want the user to be able to turn off the slide show tell the timer to stop remove the eventListener and reset the timeCount. you'll want to reset the time count incase they decide to turn the slide show back on that it waits 30 seconds and not how ever much time was left when they turn the slide show off.