A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: [F8] Looping through object properties

  1. #1
    Senior Member
    Join Date
    Mar 2004
    Posts
    120

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

  2. #2
    :
    Join Date
    Dec 2002
    Posts
    3,518

    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("*-----*");
    }
    //

  3. #3
    Senior Member
    Join Date
    Mar 2004
    Posts
    120
    Quote 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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center