Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to convert comma separated strings into a single Array in AS3 and iterate it into a loader

Posted on 2009-05-03
2
Medium Priority
?
1,081 Views
Last Modified: 2013-11-11
I have a string like this

,fotografie/prodotti/thumbs/000101.jpg,fotografie/prodotti/thumbs/000201.jpg,fotografie/prodotti/thumbs/000301.jpg,fotografie/prodotti/thumbs/000401.jpg,fotografie/prodotti/thumbs/000501.jpg,fotografie/prodotti/thumbs/000601.jpg,fotografie/prodotti/thumbs/000701.jpg,fotografie/prodotti/thumbs/000801.jpg,fotografie/prodotti/thumbs/000901.jpg,fotografie/prodotti/thumbs/001001.jpg

and i should :

- remove the first comma
- have any number of items ( i don't know how many) and add each URL into a different array's value
- iterate a loop to load the images, completing the code below


Thank You for your help
loader = new Loader();
loader.load(new URLRequest(IMAGEPATH));
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, LOADNEXTIMAGE);

Open in new window

0
Comment
Question by:fario
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 8

Accepted Solution

by:
ccarey earned 1500 total points
ID: 24291961
try this snippet

you'll need to replace the 'str' variable with your list of paths (i used 'a,b,c' for brevity) and modify the onComplete handler to do something with the thing you loaded (display it or store it or whatever)

var str = ",a,b,c";          // replace with your list of paths
var arr = str.split(",");    // turn the path string into an array, split at commas
 
/**
* load next image in queue 
*/
function loadNextImage(){
    // pop an item out of the queue, ignore blanks
    var path = "";    
    while(arr.length > 0 && path.length==0){
        path = arr.pop();        
    }
    if(path.length==0) {
       trace('nothing more to load');
       return;
    }
    
    trace('now loading ',path);
    
    var loader = new Loader();
    loader.load(new URLRequest(path));
    loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
}
 
/** 
* callback for onComplete
*/
function onComplete(evt:Event = null) : void {
	// do something with what you loaded here
	
	// load next image
	loadNextImage();
}
 
// kick off
loadNextImage();

Open in new window

0
 
LVL 1

Author Comment

by:fario
ID: 24296473
Hi

I had to made some important changes but you put me on the right way

thank you
var thumbsContainer:NpScrollingPanel = new NpScrollingPanel();
var gw:NetConnection = new NetConnection();
var percorso:Array;
var loader = new Loader();
var immagini:String = "";
var percorsoImmagini:Array;
var t:Array;
var str:String
var imagesNumber:int;
var p:int = 0;
var arr:Array;
var path:String;
 
var res:Responder = new Responder(onResult, onFault);
 
gw.connect("http://www.dbwebserver.com/semeraro/amfphp/gateway.php"); 
gw.call("SliderProdotti.loadMysqlData", res, "01");  //access to DB
 
 
 
function onResult(responds:Object):void
{
	// parse the ArrayCollection
	t = responds.serverInfo.initialData;
	creaStringaPercorsi();
 
}
 
function onFault(responds:Object):void
{
	for(var i in responds)
	{
		trace(responds[i]);
	}
}
 
 
function creaStringaPercorsi():void {
 
	for(var i:uint=0; i<t.length; i++)
	{
		immagini = immagini+","+ String(t[i][9]);
	}
	imagesNumber = t.length;
	trace("imagesNumber: "+imagesNumber);
	immagini = immagini.substring(1,immagini.length);
	str = immagini;
	arr = str.split(",");
	loadNextImage();
}
 
 
function loadNextImage(){
    // pop an item out of the queue, ignore blanks
    path = "";    
    while(arr.length > 0 && path.length==0){
        path = arr.pop();        
    }
    if(path.length==0) {
       trace('nothing more to load');
       return;
    }
    else {
    path = "http://www.dbwebserver.com/semeraro/03/"+path;
	trace('now loading '+path);
    loader.load(new URLRequest(path));
	loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete); }
}
 
/** 
* callback for onComplete
*/
function onComplete(evt:Event = null) : void {
		trace('loaded '+path);
		p++;
        // do something with what you loaded here
        if (p < imagesNumber) { 
		thumbsContainer.addContentItem(loader.content); 
        // load next image
        loadNextImage(); }
		else { 
		trace("all loaded");
		thumbsContainer.enableScrolling(); }
}

Open in new window

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a very simple example to help those of you who are still migrating from AS2 to AS3 understand the redesigned event model in AS3. In AS2.0, event functions (that is, the function to be performed when an event is fired) were stored as a pro…
While working over numerous projects I often had the requirement for doing a screen capture in AS3.0. Unfortunately I found no "ready made" solutions in google search that suited my requirements. But I did come across some great resources which help…
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question