Iterate through room properties

Post here your questions about Actionscript and Java server side extensions development.

Moderators: Lapo, Bax

Fishypants
Posts: 57
Joined: 26 Oct 2010, 14:03
Location: South Pasadena California
Contact:

Iterate through room properties

Postby Fishypants » 08 Apr 2012, 18:03

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?
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Re: Iterate through room properties

Postby rjgtav » 08 Apr 2012, 23:03

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
}
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
Fishypants
Posts: 57
Joined: 26 Oct 2010, 14:03
Location: South Pasadena California
Contact:

Re: Iterate through room properties

Postby Fishypants » 09 Apr 2012, 00:34

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!

Return to “Server Side Extension Development”

Who is online

Users browsing this forum: No registered users and 44 guests