Using [Obj obj] in Director

Need help with SmartFoxServer? You didn't find an answer in our documentation? Please, post your questions here!

Moderators: Lapo, Bax

User avatar
Carl Lydon
Posts: 298
Joined: 12 Nov 2007, 16:15
Location: NYC
Contact:

Using [Obj obj] in Director

Postby Carl Lydon » 12 Nov 2007, 16:32

Hi,

This may be a bit off topic but here goes...

I'm converting a Director project from the MUS to Smartfox. I'm able to open up these [Obj obj] black boxes on the Flash side, and construct arrays to be sent to Director, but it's clunky. I'd rather have Director grab objects from the Flash sprite and then open them up on the Director side. The problem is that I can't find the lingo equivelent of:

for (var i in lUsersObj) {
//Get each user from the userlist
luser = (lUsersObj[i]);
Lname = luser["name"]+"";
id = luser["id"]+"";
}

specifically, what is th elingo equivelent of:

for (var i in lUsersObj) {

???

I can get the Flash object in, and some of them I can get properties for if I know the structure, but with a userlists I can't get the length of the array using userlist.length, or count(userlist) because it's like a property list using the pID number, which can be anything from 0 to a million....

I hope this makes sense. Any ideas?
User avatar
potmo
Posts: 154
Joined: 02 Feb 2007, 14:28
Location: Stockholm Sweden
Contact:

Postby potmo » 13 Nov 2007, 10:11

to do this

Code: Select all

for (var i in lUsersObj) {
 luser = (lUsersObj[i]);
trace(luser["name"])
}

in lingo you do this

Code: Select all

repeat with luser in lUserObj
put luser.name
end repeat


This is when you have a list (lUserObj) structured like this

[[#name:"Bill", #age:12], [#name: "Fred", #age: 99], [#name: "frank", #age: 118]]

(and you can have objects instread of propLists in that list)

Its worse if lUserOj is an Object instead of an list.
Then you will have to do something like this i think.

Code: Select all

repeat with i = 1 to lUserObj.count
tKey = lUserObj.getPropAt(i)
tValue  = luserObj[i]
end repeat


it might work with "repeat with x in y" on objects as well. That you will have to test.

Good Luck!
Nisse Bergman
Raketspel
User avatar
Carl Lydon
Posts: 298
Joined: 12 Nov 2007, 16:15
Location: NYC
Contact:

Thank you so much

Postby Carl Lydon » 13 Nov 2007, 15:09

That was a head scratcher for me. This will make my code cleaner and more flexible. Thanks!
User avatar
Carl Lydon
Posts: 298
Joined: 12 Nov 2007, 16:15
Location: NYC
Contact:

Actually....

Postby Carl Lydon » 13 Nov 2007, 15:49

I'm having a hard time.

I tried:

gRoomObj= sprite(gSFSprt).getVariable("gRoomObj", false)
gUsers = gRoomObj.getUserList()
put gUsers.ilk
repeat with user in gUsers
put "user=" && user.name
end repeat
end repeat

The gRoomObj comes in fine. The getUserList() function seems to work fine ; I don't get an error for that and gUsers.ilk= #FlashObject.

But I don't get any results from the repeat loop; it seems like it doesn't iterate through even once, so the "user in gUsers" isn't working.

User is another object. gRoomObj contains a userlist object that contains an object for each user.

Also, count(gUser) and gUser.length both come out <void> so that won't work.

gRoomObj.getUserCount() does work for seeign how many users are in the room.


-Carl
User avatar
Carl Lydon
Posts: 298
Joined: 12 Nov 2007, 16:15
Location: NYC
Contact:

Doesn't work

Postby Carl Lydon » 13 Nov 2007, 16:42

Oh well, that doesn't work. For now I'll go back to what I was doing before, which was extracting each user from the userlist on the Flash side and arranging them in a sensible linear list that I can then grab on the Director side and iterate through in a normal way...
User avatar
potmo
Posts: 154
Joined: 02 Feb 2007, 14:28
Location: Stockholm Sweden
Contact:

Postby potmo » 13 Nov 2007, 21:44

if you can wait until tomorrow i can send you my Director API for smartfox, im not at work right now.

Anyway if anyone else wants it its almoust done. Anyone can get it for free under some kind of "GNU public licence" if you promise to redistribute your contributions.
Nisse Bergman

Raketspel
User avatar
Carl Lydon
Posts: 298
Joined: 12 Nov 2007, 16:15
Location: NYC
Contact:

Yes...

Postby Carl Lydon » 13 Nov 2007, 23:26

Yes, and we should talk about you doing an article on using SF in Director for

Shockwaveserver.com

I imagine you're the top expert on that, and it's a very specialized topic that is hard to find information on.

Return to “SmartFoxServer 1.x Discussions and Help”

Who is online

Users browsing this forum: No registered users and 81 guests