Link to home
Start Free TrialLog in
Avatar of lowsky13
lowsky13

asked on

getting individual values from array

I have information in an array. It traces out. However, how do I call just one at a time? I have file locations to call photos for my loader. I want them to load individually not as a whole list. How do I split them up? Also, how do I get the number of items I have in my array? I have tried "length" but that only gave me the total characters..not the number of items.

I'm using AS3.
Avatar of go4ejjohn
go4ejjohn

I think what you have is a string not array.
firstly you should convert string in to array.
var str = old_str.split(",");

here old_str is the string what u think it as an array.
str is an array you can then get the length of an array.

Regards,
Jon
Avatar of lowsky13

ASKER

i figured out how to get the length of the array. i cannot now figure out how to split the array into individual values...below is my code.

picnumber is how many items there are and ppic are all the values. I need to be able to get individual values...

I want to load the first value into my loader...then if I click a button have it load the next one and/or go to the previous. How would I go about that? Isn't ppic already in an array?
//connect to xml file
var photoArray:Array;
var xmlConnect:URLLoader = new URLLoader();
var xmlData:XML = new XML();
 
xmlConnect.addEventListener(Event.COMPLETE, LoadXML);
 
xmlConnect.load(new URLRequest("xml.xml"));
 
function LoadXML(e:Event):void {
 
xmlData = new XML(e.target.data);
loadData(xmlData);
 
}
 
function loadData(playlist:XML):void {
	var picnumber:Number = playlist.listitem.ppic.length();
	var ppic:String = playlist.listitem.ppic.text();
 
//put photos into an array

Open in new window

ppic is a string and i can C it clearly in your declaration. can you trace ppic for me?

Regards,
Jon
A trace of ppic outputted my two values butted up against each other. Also traced picnumber and got 2. So they are both tracing correctly. I just need to be able to get each value dynamically.
hey tell me what is the output when you trace ppic ?

Jon
I don't see why you need the exact results because the content doesn't matter but it is..

string1string2

This is correct but I need to know how to call string2 independent of string1. My xml files will constantly change so it needs to be dynamic.
Is there a way that you can get your out put
string1,string2 format (that is with a , seperated)?

Jon
I have done this but I get the same result...no comma or anything broken up...also no errors though. What do you suggest?
//put photos into an array
 
var str = ppic.split(",");
trace(str);

Open in new window

Could you please show me your XML file..

Jon
ASKER CERTIFIED SOLUTION
Avatar of go4ejjohn
go4ejjohn

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial