Skip to main content
August 9, 2011
Answered

How do you get incremented xml data in a for statement?

  • August 9, 2011
  • 1 reply
  • 393 views

Hello,

I am importing data using xml and getting incremented data that looks like this

peopleObject.name0

peopleObject.phone0

peopleObject.image0

peopleObject.name1

peopleObject.phone1

peopleObject.image1

And now i am trying to use that information using a for statement but i do not know how i can add the incremented number at the end. I tried to add a "+i" like this

for(var i=0; i <= peopleTotal ;i++){
     var newMC:MovieClip = placeHolder.attachMovie("peopleMovie", "peopleMovie_"+i, i);     
     newMC._x = 100;
     newMC._y = ya;
     newMC.peoplename.text = peopleObject.name+i;
          trace(peopleObject.name+i+ " name+i")
     newMC.peopleimg = peopleObject.image+i;
     ya += newMC._height;
}

So any idea how can I access the data that is in an incremented variable in a seperate for statement? Let me know if i didnt explain good enough.

Thanks,

Randy

This topic has been closed for replies.
Correct answer kglad

use array notation:

peopleObject["name"+i]=whatever

peopleObject['phone"+i]=whateverelse;

etc.

1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
August 10, 2011

use array notation:

peopleObject["name"+i]=whatever

peopleObject['phone"+i]=whateverelse;

etc.

August 10, 2011

hi Kglad,

im sorry i made a mistake i am actually looking to get

peopleObject0.name
peopleObject0.phone
peopleObject0.image
peopleObject1.name
peopleObject1.phone
peopleObject1.image

etc...

I tried to apply your coding like this

["peopleObject"+i].name

but i am not able to get it to work. Any Ideas?

Thanks

kglad
Community Expert
Community Expert
August 10, 2011

use:

this["peopleObject"+i].name

etc