Skip to main content
Inspiring
Jan 24, 2009 8:01 AM UTC
Answered

iterating a sharedobject server side

I am trying to iterate a shared object on the server side and get the slot name. For example I have a shared object with slots names A, B, C, D, etc. How do I iterate the slots and get the slot name? Should be a pretty simple question to answer, but the answer is alluding me.
    This topic is closed to new replies. Start a new post to keep the conversation going.
    jonporCorrect answer
    Inspiring
    Jan 29, 2009 11:19 AM UTC
    thanks for the pointers. I was on the right track but a little off. I would have expected the slotName iterator to be key/name of the slot, but I needed to reference it as SharedObjectSlots [slotName ]; Still don't understand that but at least it is working.

    var SharedObjectSlots = mySO.getPropertyNames();

    for (slotName in SharedObjectSlots ){
    trace ( "name of slot = " + SharedObjectSlots [slotName ] );
    }

    4 replies

    Jan 26, 2009 8:22 PM UTC
    Yup. Thanks for catching my code error.
    Translate
    jonporAuthorCorrect answer
    Inspiring
    Jan 29, 2009 11:19 AM UTC
    thanks for the pointers. I was on the right track but a little off. I would have expected the slotName iterator to be key/name of the slot, but I needed to reference it as SharedObjectSlots [slotName ]; Still don't understand that but at least it is working.

    var SharedObjectSlots = mySO.getPropertyNames();

    for (slotName in SharedObjectSlots ){
    trace ( "name of slot = " + SharedObjectSlots [slotName ] );
    }
    Translate
    Jan 24, 2009 4:13 PM UTC
    You need to use the getPropertyNames method. It returns a list of the property names in the SO as an array, and then you can iterate through that array. The items in the array are just the property names, not the properties themselves. To get the SO property, you need to use getProperty as you iterate through the array of property names:

    var list = mySO.getPropertyNames();
    for(var a=0; a<list.length; a++){
    var currentProperty = mySO.getProperty(a);
    // do something with the current property
    }
    Translate
    Inspiring
    Jan 26, 2009 7:15 PM UTC