-
[F8] Looping through object properties
Code:
pic[
{
clip2:{
clipRotation:{
data:"36.21",
attributes:{}
},
clipW:{
data:"83.7",
attributes:{}
},
clipH:{
data:"83.7",
attributes:{}
},
clipY:{
data:"74",
attributes:{}
},
clipX:{
data:"198",
attributes:{}
},
clip:{
data:"testing/cliprts/friendship4.gif",
attributes:{}
},
Depth:{
data:"2",
attributes:{}
},
data:null,
attributes:{}
},
texts1:{
rotation:{
data:"0",
attributes:{}
},
width:{
data:"255.15",
attributes:{}
},
height:{
data:"41.15",
attributes:{}
},
y:{
data:"124",
attributes:{}
},
x:{
data:"22",
attributes:{}
},
color:{
data:"ff3366",
attributes:{}
},
type:{
data:"Nuri-Black",
attributes:{}
},
Text:{
data:"Click to edit text",
attributes:{}
},
Depth:{
data:"1",
attributes:{}
},
data:null,
attributes:{}
},
clip0:{
clipRotation:{
data:"0",
attributes:{}
},
clipW:{
data:"62",
attributes:{}
},
clipH:{
data:"62",
attributes:{}
},
clipY:{
data:"67",
attributes:{}
},
clipX:{
data:"61",
attributes:{}
},
clip:{
data:"testing/cliprts/friendship2.gif",
attributes:{}
},
Depth:{
data:"0",
attributes:{}
},
data:null,
attributes:{}
},
data:null,
attributes:{}
}
]
i load this data from an xml and need to place the images in stage according to details given.i convert the xml to an object so its convenient.
now i need to loop through this data (properties of the pic object) and load each image and set their properties.
problem is i cant figure out how to loop through the properties as there can be any number of them. here you get 3 (clips0,texts1,clips2)..
can anyone help?
-
Maybe you can adapt this to what you are trying to do...
Note: In this example the outer braces were removed from the pic object.
Code:
stop();
var pic = new Object();
pic = {clip2:{clipRotation:{data:"36.21", attributes:{}}, clipW:{data:"83.7", attributes:{}}, clipH:{data:"83.7", attributes:{}}, clipY:{data:"74", attributes:{}}, clipX:{data:"198", attributes:{}}, clip:{data:"testing/cliprts/friendship4.gif", attributes:{}}, Depth:{data:"2", attributes:{}}, data:null, attributes:{}}, texts1:{rotation:{data:"0", attributes:{}}, width:{data:"255.15", attributes:{}}, height:{data:"41.15", attributes:{}}, y:{data:"124", attributes:{}}, x:{data:"22", attributes:{}}, color:{data:"ff3366", attributes:{}}, type:{data:"Nuri-Black", attributes:{}}, Text:{data:"Click to edit text", attributes:{}}, Depth:{data:"1", attributes:{}}, data:null, attributes:{}}, clip0:{clipRotation:{data:"0", attributes:{}}, clipW:{data:"62", attributes:{}}, clipH:{data:"62", attributes:{}}, clipY:{data:"67", attributes:{}}, clipX:{data:"61", attributes:{}}, clip:{data:"testing/cliprts/friendship2.gif", attributes:{}}, Depth:{data:"0", attributes:{}}, data:null, attributes:{}}, data:null, attributes:{}};
for (i in pic) {
trace("* this: " + i);
for (j in pic[i]) {
trace("* has: " + j);
for (k in pic[i][j]) {
trace("* and: " + k + " " + pic[i][j][k]);
}
}
trace("*-----*");
}
//
-
Originally Posted by dawsonk
Note: In this example the outer braces were removed from the pic object.
Code:
stop();
var pic = new Object();
pic = {clip2:{clipRotation:{data:"36.21", attributes:{}}, clipW:{data:"83.7", attributes:{}}, clipH:{data:"83.7", attributes:{}}, clipY:{data:"74", attributes:{}}, clipX:{data:"198", attributes:{}}, clip:{data:"testing/cliprts/friendship4.gif", attributes:{}}, Depth:{data:"2", attributes:{}}, data:null, attributes:{}}, texts1:{rotation:{data:"0", attributes:{}}, width:{data:"255.15", attributes:{}}, height:{data:"41.15", attributes:{}}, y:{data:"124", attributes:{}}, x:{data:"22", attributes:{}}, color:{data:"ff3366", attributes:{}}, type:{data:"Nuri-Black", attributes:{}}, Text:{data:"Click to edit text", attributes:{}}, Depth:{data:"1", attributes:{}}, data:null, attributes:{}}, clip0:{clipRotation:{data:"0", attributes:{}}, clipW:{data:"62", attributes:{}}, clipH:{data:"62", attributes:{}}, clipY:{data:"67", attributes:{}}, clipX:{data:"61", attributes:{}}, clip:{data:"testing/cliprts/friendship2.gif", attributes:{}}, Depth:{data:"0", attributes:{}}, data:null, attributes:{}}, data:null, attributes:{}};
for (i in pic) {
trace("* this: " + i);
for (j in pic[i]) {
trace("* has: " + j);
for (k in pic[i][j]) {
trace("* and: " + k + " " + pic[i][j][k]);
}
}
trace("*-----*");
}
//
Thanks buddy helped a lot ;-)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|