all groups > flash actionscript > february 2006 >
You're in the

flash actionscript

group:

loop through all variables in an object


loop through all variables in an object stephan.k
2/2/2006 9:45:55 PM
flash actionscript:
Hi Everyone

I am trying to loop through all the variables in an object.

The object contains variables in the following format:

storyObj = new Object();
storyObj.id_1 = "Hello"
storyObj.id_200 = "Hello"
storyObj.id_23 = "Hello"

the id's are not in any order of any kind.

any help appreciated.

Thanks

STephan

Re: loop through all variables in an object stephan.k
2/2/2006 9:49:19 PM
I just tried this ... one more step is missing:

storyVars = new Object();

storyVars.id_1 = "Story one"
storyVars.id_21 = "Story two"
storyVars.id_13 = "Story three"
storyVars.id_14 = "Story four"
storyVars.id_15 = "Story five"
storyVars.id_222 = "Story six"
storyVars.id_2434 = "Story seven"
storyVars.id_242424 = "Story eight"

for(i in storyVars){
trace(this.i)
}
Re: loop through all variables in an object stephan.k
2/2/2006 10:12:03 PM
got it:

storyVars = new Object();

storyVars.id_1 = "Story one"
storyVars.id_21 = "Story two"
storyVars.id_13 = "Story three"
storyVars.id_14 = "Story four"
storyVars.id_15 = "Story five"
storyVars.id_222 = "Story six"
storyVars.id_2434 = "Story seven"
storyVars.id_242424 = "Story eight"

trace(storyVars)

for(i in storyVars){
trace(storyVars)
}
Re: loop through all variables in an object stephan.k
2/2/2006 10:44:15 PM
thanks! Sorry I didn't see your post.

Re: loop through all variables in an object Jeckyl
2/3/2006 12:00:00 AM
[quoted text, click to view]

try this for the trace ...

trace("var " + i + " = " + this [ i ] );

that should then show you the variable name ( i ) and the value ( this [
i ] )

Jeckyl


AddThis Social Bookmark Button