We help IT Professionals succeed at work.

getting individual values from array

Last Modified: 2013-11-11
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.
Watch Question

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.



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);
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?



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 ?



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


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)?



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(",");

Open in new window

Could you please show me your XML file..

This one is on us!
(Get your first solution completely free - no credit card required)

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.