onUserEnterRoom question - avatarChat
Posted: 10 Mar 2010, 05:42
Please see my comments in the code below.
It seems strange to set up the user avatar when they join the room, because the other users in the room are notified that this new user entered the room before the new user can even set it's own properties. Please set me straight on this.
Code: Select all
function onUserEnterRoom( evt:SFSEvent ):void
{
var user:User = evt.params[ "user" ]
var userId:Number = user.getId()
var userName:String = user.getName()
var uVars:Object = user.getVariables()
var mc:Avatar = Avatar( avatarMC.getChildByName( "avatar_" + userId )) //if the user is just entering the room, how can an avatar with his userId already exist?
mc = new Avatar //doesn't this line render the previous line useless?
mc.id = "avatar_" + userId
mc.name = "avatar_" + userId
avatarMC.addChild( mc )
//the following two lines trace out as "undefined" for me. I believe this is because the onUserEnterRoom event is received before the user sets up their own variables (which is done in "SetupMyAvatar", which is called from onJoinRoom).
mc.x = uVars.px
mc.y = uVars.py
mc.disc.gotoAndStop( uVars.col )
mc.uname.text = user.getName()
}