Page 1 of 1
Iterate through room properties
Posted: 08 Apr 2012, 18:03
by Fishypants
Hey everyone, I am using Smartfox 1.x with Actionscript and I am wondering how to go about iterating through all the room properties I have set up. I can see the size of the properties array by using Room.properties.size(), but as far as iterating through these values I don't know the correct syntax. Could someone point me in the right direction?
Re: Iterate through room properties
Posted: 08 Apr 2012, 23:03
by rjgtav
Hello.
As the
properties property is a HashMap, you can do it like you do in Java, by using the Iterator. It will stay something like:
Code: Select all
var iterator = room.properties.entrySet().iterator();
while(iterator.hasNext()){
var obj = iterator.next();
trace("key: "+obj.getKey()+", value: "+obj.getValue());
iterator.remove();//// avoids a ConcurrentModificationException
}
Re: Iterate through room properties
Posted: 09 Apr 2012, 00:34
by Fishypants
Interesting, well thank you for the code example rjgtav. I have since reworked my code, so instead of individual properties for say "enemyLocationA", "enemyLocationB", etc, I just have an "enemyLocations" array property. Then I just get that property and iterate through it. Seems easier and cleaner. Thank you for the code example though, I might still need to use this. cheers!