FORUMS: list search recent posts

Displaying images in a folder

COW Forums : Adobe Flash

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Marc Jordan
Displaying images in a folder
on Dec 18, 2008 at 10:20:57 pm

Howdy. I'd like to cycle through all images in a folder and display each one based on a timer. I'd like to add/remove files to/from the folder so I'd rather not have the file list built into the flash app. I'm still green with Flash... can someone please point me to tutorials/info that can help me figure out how to do this?


Return to posts index

Marc Jordan
Re: Displaying images in a folder
on Dec 21, 2008 at 2:46:18 am

Well, I'm getting a little closer. See the CS3 Actionscript3 code below for what I have hacked together so far from various examples/tutorials. The timer code is working just fine, but the image loading isn't working. I verified that the image path string is getting created properly, but I don't see an image loaded on the stage. I know that I'm probably missing some things: how to set the location of the image, hooking it into the stage, etc. I'm not sure of the right questions to ask at this point...


package {
import flash.utils.Timer;
import flash.events.*;
import flash.display.*;
import flash.net.*;

public class flash_image_loader extends MovieClip {

//*************************
// Properties:

public var source:*;
public var loader:Loader;
public var loaderIndex:Number = 1;
public var loaderNumFiles:Number = 3;

//*************************
// Constructor:

public function flash_image_loader() {
// Image timer
var myTimer:Timer = new Timer(5000, 0);
myTimer.addEventListener(TimerEvent.TIMER, timerHandler);

// Image loader
loader = new Loader();

// Load first image...
loadImage();

// Start the timer
myTimer.start();

}

//*************************
// Event Handling:

public function timerHandler(event:TimerEvent):void {
loaderIndex++;
if(loaderIndex > loaderNumFiles) {
loaderIndex = 1;
}
trace("timerHandler: " + loaderIndex);
loadImage();
}

public function getPath():String
{
return ("images/image_"+loaderIndex+".jpg");
}

public function loadImage():void
{
var imagePath;
var urlRequest:URLRequest;

imagePath = getPath();
trace("imagePath: " + imagePath);
urlRequest = new URLRequest(url);
loader.load(new URLRequest(imagePath));
}
}
}




Return to posts index

Marc Jordan
Re: Displaying images in a folder
on Dec 21, 2008 at 8:26:40 pm

Got it basically working:

http://www.wheelstickandpedal.com WIP

I've got another thread going in the Dreamweaver section, containing the planned site layout:

Dreamweaver site layout

Code is below. The loadImage function in the previous version was a little goofed up. With that fixed, my problem was that the script wasn't hooked to a movie clip. So, I created a movie clip with mask and named it loadPic.

For some reason it is cutting off the images. The movie clip & images are all sized the same, so I'm not sure yet what is going on. I'd also like to have the images fade into each other and not have the movie go blank then the next image tween in. The transparent overlay needs some work as well to make it show up better under more background color conditions.

I'd also like to get rid of the hard-coded loaderNumFiles and find a way to count the images dynamically so I can just add new files to the image directory w/o having to update the script.


import flash.utils.Timer;
import flash.events.*;
import flash.display.*;
import flash.net.*;
import fl.transitions.Tween;
import fl.transitions.easing.*;

var loaderIndex:Number = 1;
var loaderNumFiles:Number = 6;
var imageLoader:Loader = new Loader();
imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
loadPic.addChild(imageLoader);

var myTimer:Timer = new Timer(5000, 0);
myTimer.addEventListener(TimerEvent.TIMER, timerHandler);

// Load first image...
loadImage();

// Start the timer
myTimer.start();

function timerHandler(event:TimerEvent):void {
loaderIndex++;
if(loaderIndex > loaderNumFiles) {
loaderIndex = 1;
}
trace("timerHandler: " + loaderIndex);
loadImage();
}

function getPath():String {
return ("images/image_banner_"+loaderIndex+".jpg");
}

function loadImage():void {
var imagePath;
var urlRequest:URLRequest;

imagePath = getPath();
trace("imagePath: " + imagePath);
urlRequest = new URLRequest(imagePath);
imageLoader.load(urlRequest);
}

function completeHandler(event:Event):void {
trace("preload complete");
var imageTween:Tween = new Tween(imageLoader, "alpha", Strong.easeOut, 0, 1, 3, true);
}




Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]