Skip to main content
Inspiring
January 24, 2009
Answered

iterating a sharedobject server side

  • January 24, 2009
  • 2 replies
  • 602 views
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 has been closed for replies.
    Correct answer jonpor
    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 ] );
    }

    2 replies

    January 26, 2009
    Yup. Thanks for catching my code error.
    jonporAuthorCorrect answer
    Inspiring
    January 29, 2009
    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 ] );
    }
    January 24, 2009
    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
    }
    Inspiring
    January 26, 2009