lo que busco es que al terminar la descarga de todos los archivos la clase me lleve a otro fotograma, o cargue solamente uno de los archivos cargados, ya que lo que actualmente sucede es que al terminar de descargar todos los archivos los abre y los muestra en el stage.
aquí les dejo el link donde puede descargar el preloader y todos los archivos:
[url=http://code.google.com/p/as3-multiple-file-preloader/downloads/list][/url]
y el codigo de la clase (son dos clases la verdad):
Código ActionScript :
/*
# Multiple file preloader example
# © Michel van der Wal | Team 2.0
# This file needs 'Preload.as' to compile
*/
package com.team2p0
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.ProgressEvent;
public class Main extends Sprite
{
var pre:Preload; // declare the preload class
public function Main()
{
pre = new Preload(["1.jpg","2.jpg","3.jpg"]); // instantiate and add the files to be preloaded as an array
pre.addEventListener("preloadProgress", onPreloadProgress);
pre.addEventListener("preloadComplete", onPreloadComplete); // add listeners for progress
}
private function onPreloadProgress(e:Event)
{
textfield.text = e.target.percLoaded + "% loaded"; // textfield is a dynamic textfield on the stage
this.loaderBar.width = e.target.percLoaded * 2; // loaderBar is an mc on the stage
}
private function onPreloadComplete(e:Event)
{
this.loaderBar.width = 100 * 2;
textfield.text = "Loading complete";
pre.removeEventListener("preloadComplete", onPreloadComplete); // garbage collect
pre.removeEventListener("preloadProgress", onPreloadProgress);
trace(pre.objects); // get the loaded objects as an array
// showObjects(pre.objects); // try this to see the loaded images through the function 'showObjects' below
}
private function showObjects(o:Array) // ESTA ES LA FUNCION QUE HABRIA QUE CAMBIAR.
{
var stageWidth:uint = stage.stageWidth - 10;
var offSet:uint = 10;
for (var i:int=0; i<o.length; i++)
{
var imageWidth:Number = stageWidth / o.length - (offSet / o.length);
var ar:Number = o[i].height / o[i].width;
var imageHeight:Number = imageWidth * ar;
o[i].width = imageWidth;
o[i].height = imageHeight;
o[i].x = imageWidth * i + offSet;
o[i].y = offSet;
addChild(o[i]);
}
}
}
}la segunda clase:
Código ActionScript :
/*
# Multiple file preloader: Preloader class
# Preloads multiple swfs and/or images
# Accepts an array with strings containing the files to be loaded
# Dispatches a progress event when loading is in progress
# Returns the total precentage loaded with getter method 'Preloader.percLoaded'
# Dispatches a complete event when total loading is complete
# Returns an array with objects with the loaded files
get the array through getter method 'Preloader.objects'
# instantiate like this:
# var pre:Preload = new Preload(["1.jpg","2.jpg","3.jpg"]);
# pre.addEventListener("preloadProgress", onPreloadProgress);
# pre.addEventListener("preloadComplete", onPreloadComplete);
*/
package
{
import flash.display.Sprite;
import flash.display.Loader;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.net.URLRequest;
public class Preload extends Sprite
{
public var objectsArray:Array = new Array(); // holds the the loaded files
public var pLoaded:int = 0; // defaults the loaded percentage to 0
private var itemsArray:Array = new Array(); // holds all the items to be loaded
private var totalItems:int; // holds the total items to be preloaded
private var currItem:int = 1; // defaults the current preloaded item to 1
public function Preload(_itemsArray:Array)
{
itemsArray = _itemsArray;
totalItems = _itemsArray.length;
loadOne(currItem - 1, itemsArray); // load the first item
}
private function loadOne(what:int, _itemsArray:Array):void
{
var ldr:Loader = new Loader();
ldr.load(new URLRequest(_itemsArray[what].toString()));
ldr.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onInternalProgress);
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, onInternalComplete);
}
private function onInternalProgress(e:Event):void
{
var temp:int = Math.ceil((((e.target.bytesLoaded / e.target.bytesTotal)*100 * currItem) / totalItems));
if (temp > pLoaded) {
pLoaded = temp; // avoid the precentage to drop
}
trace(pLoaded);
dispatchEvent(new Event("preloadProgress")); // call the parent class with a progress update
}
private function onInternalComplete(e:Event):void
{
objectsArray.push(e.target.content); // add a loaded object to the objects array
currItem += 1; // increment the current item to be loaded
if (objectsArray.length == totalItems) {
e.target.removeEventListener(ProgressEvent.PROGRESS, onInternalProgress); // garbage collect
e.target.removeEventListener(Event.COMPLETE, onInternalComplete);
dispatchEvent(new Event("preloadComplete")); // when all objects are loaded, call the parent class
} else {
loadOne(currItem - 1, itemsArray); // load the next one
}
trace("complete");
}
public function get percLoaded():int
{
return pLoaded; // returns the loaded percentage of all files to be preloaded
}
public function get objects():Array
{
return objectsArray; // returns the loaded files as an array
}
}
}
bueno, si alguien ha trabajado con este preloader, o sabe como cambiar la funcion para abrir los archivos cargados, le agradeceria infinitamente su ayuda, ya que llevo mucho tiempo intentandolo y ya no se como hacerlo.
saludos.
rodrigo.
