Unable to remove avatars from stage

Post here your questions about the Flash / Flex / Air API for SFS2X

Moderators: Lapo, Bax

Sfulk
Posts: 54
Joined: 06 Jul 2012, 17:02

Unable to remove avatars from stage

Postby Sfulk » 28 Mar 2015, 02:45

Hello Everyone,
I recently added a room list to the flash Simple MMO World example. I am having problems removing the avatars of the previous room from the stage before joining the new room. I looked at the Avatar Chat example and saw that they used this:

Code: Select all

while (panel_chat.avArea.avContainer.numChildren > 0)
            removeAvatar(getAvatar(0))

I modified it to this and added to the onRoomJoin function:

Code: Select all

while (mapArea.avContainer.numChildren > 0)
            removeAvatar(getAvatar(0))

This isn’t working though, when I initially join a room I get this error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.

If I join a room after that I get the following error:
TypeError: Error #2007: Parameter child must be non-null.
at flash.display::DisplayObjectContainer/removeChild()

I looked through the Avatar Chat example and saw that the removeAvatar and getAvatar functions are identical to the removeAvatar and getAvatar functions in the Simple MMO World example so I’m not sure why I’m getting this error. Any help would be greatly appreciated.
Thanks,
Scott
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: Unable to remove avatars from stage

Postby Bax » 30 Mar 2015, 14:23

As it regards the error on the first join, maybe mapArea or avContainer objects are not yet available on the stage?
In fact the Simple MMO example, in the onRoomJoin listener, moves the playhead of the Flash timeline to a new frame. The content of the frame must be drawn before you can access it.

About the second error, it is hard to say. It seems you are doing something like "removeChild(null)". The getAvatar method requires a username to be passed. How do you know what name to pass?
Paolo Bax
The SmartFoxServer Team
Sfulk
Posts: 54
Joined: 06 Jul 2012, 17:02

Re: Unable to remove avatars from stage

Postby Sfulk » 31 Mar 2015, 01:26

Hey Bax,

Thanks for the help, what is the proper way to remove all avatars? Like get a userList from the previous room and pass all of those usernames through or is there a way to just remove all instances of the avatar movie clip to basically reset the stage?

Thanks again,
Scott
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: Unable to remove avatars from stage

Postby Bax » 31 Mar 2015, 07:09

If you have a display object acting as a container for all the avatars, you may cycle through its children and remove them.
Take a look at this for example: http://stackoverflow.com/questions/5082 ... l-children
Paolo Bax
The SmartFoxServer Team
Sfulk
Posts: 54
Joined: 06 Jul 2012, 17:02

Re: Unable to remove avatars from stage

Postby Sfulk » 03 Apr 2015, 01:38

Thanks a lot Bax, I got it working. :D

Return to “SFS2X ActionScript 3 API”

Who is online

Users browsing this forum: No registered users and 19 guests