Forum ActionScript 3.0 *SOLVED* RoomInfo

Problems and discussions relating to ActionScript 3.0 here.

*SOLVED* RoomInfo

Postby angelicstickman » June 18th, 2012, 11:51 pm

How do I create an instance of RoomInfo? I've browsed the internet but can't find an answer.

I understand that it has to be created through client.multiplayer.listRooms but I don't know how.
I tried the following code which throws an error: //TypeError: Error #1010: A term is undefined and has no properties.

Code: Select all
client.multiplayer.listRooms("MyGame", null, 1, 0, function(rooms:Array){trace("Online Users:"+rooms[0].onlineUsers)}, null);
Last edited by angelicstickman on June 20th, 2012, 3:01 pm, edited 1 time in total.
angelicstickman
 
Posts: 7
Joined: June 17th, 2012, 1:15 pm

Re: RoomInfo

Postby Henrik » June 19th, 2012, 11:10 am

Henrik
.IO
 
Posts: 1832
Joined: January 4th, 2010, 1:53 pm

Re: RoomInfo

Postby angelicstickman » June 19th, 2012, 12:03 pm

I've read through that but am still not very clear. For instance it has a code snippet:

Code: Select all
function(rooms:Array<RoomInfo>)


My flash program does not recognise <RoomInfo>. It thinks < is a less than sign.
If it's only meant to be a note then using function(rooms:Array) is not working for me. When tracing rooms it merely says undefined.
angelicstickman
 
Posts: 7
Joined: June 17th, 2012, 1:15 pm

Re: RoomInfo

Postby Benjaminsen » June 20th, 2012, 12:57 pm

Rooms are not persistent, IE they do not exist except when a user is connected to them.
Thus for you to make a list room with a result you must first actually create a room. The below snippet is an sure fire way of triggering a valid result.

Code: Select all
client.multiplayer.createJoinRoom("test", "bounce", true, {},{}, function(con:Connection):void{
    client.multiplayer.listRooms("bounce", null, 10, 0, function(rooms:Array):void{
   for( var a:int=0;a<rooms.length;a++){
         trace(rooms[a] as RoomInfo)
      }
   })
})


Notice that there is a lot of things that can go wrong here. IE you could have a crash bug in RoomCreated or UserJoined which prevents the room from being created and thus gives you an empty result array from rooms.

That the documentation is written as below is on purpose, to show developers which type of objects are returned in the array.
Code: Select all
function(rooms:Array<RoomInfo>)


Naturally a better solution would be to return a Vector.<RoomInfo> but we wanted maximum computability with old flash versions.
Benjaminsen
.IO
 
Posts: 1444
Joined: January 12th, 2010, 11:54 am
Location: Denmark

Re: RoomInfo

Postby angelicstickman » June 20th, 2012, 3:01 pm

Brilliant! Thanks very much! :)
angelicstickman
 
Posts: 7
Joined: June 17th, 2012, 1:15 pm


Return to ActionScript 3.0



cron