using the Iterator

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

dingo
Posts: 98
Joined: 27 Jan 2009, 21:34

using the Iterator

Postby dingo » 26 Jan 2011, 13:09

Hi

How would i go about getting the current Object when using the Iterator to go through an SFSArray?

Code: Select all

while(mySFSArray.iterator().next())
{
     myString += mySFSArray.???
}


I'm looking for something like mySFSArray.get();
Sure i could use mySFSArray.getUtfString(i), but then i would better use a for loop to keep track of i.

many thanks.
dingo
Posts: 98
Joined: 27 Jan 2009, 21:34

Postby dingo » 26 Jan 2011, 13:14

um, ok.

next() returns the actual object, so:

Code: Select all

while(mySFSArray.iterator().hasNext())
{
          myString += mySFSArray.iterator().next();
}


problem solved
:roll:
User avatar
Lapo
Site Admin
Posts: 23009
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 27 Jan 2011, 15:26

I am not sure if I understand. There is no iterator() method on the SFSArray class. Iterating over an SFSArray can be done sequentially:

Code: Select all

for (var i:int = 0; i < sfsArr.size(); i++)
{
   // etc...
}
Lapo
--
gotoAndPlay()
...addicted to flash games
dingo
Posts: 98
Joined: 27 Jan 2009, 21:34

Postby dingo » 27 Jan 2011, 18:36

If I understand correctly, SFSArray & SFSObject contain an iterator:
http://docs2x.smartfoxserver.com/api-do ... Array.html
dingo
Posts: 98
Joined: 27 Jan 2009, 21:34

Postby dingo » 27 Jan 2011, 18:46

Lapo, how would i loop through an SFSObject?

I used

Code: Select all

ISFSObject myObj = currentRoom.getVariable("myObj").getSFSObjectValue();

for(String key:myObj.getKeys())
{
    trace(myObj.getUtfString(key));
}


but it creates an infinite loop
User avatar
Lapo
Site Admin
Posts: 23009
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 27 Jan 2011, 19:20

Ah sorry... you mean on the server side :) Yep, that's right.
As regards the infinite loop thing I have no clue.
What happens if you trace the value of myObj.getKeys()? That's supposed to be a set of Strings... with a finite number of elements.
Lapo

--

gotoAndPlay()

...addicted to flash games
dingo
Posts: 98
Joined: 27 Jan 2009, 21:34

Postby dingo » 27 Jan 2011, 19:57

sorry, my bad.

the code above with String key:myObj.getKeys() works just fine.

thanks for the help!

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 68 guests