Avatar added to stage

Post here your questions about the OpenSpace 2.x or notify bugs and suggestions.

Moderators: Lapo, Bax

Post Reply
clouting
Posts: 17
Joined: 18 May 2011, 13:57

Avatar added to stage

Post by clouting »

Hi,

Is there any method to check when the avatar has actually been added from inside the avatar class. I am trying to attach an event listener to the stage to check for mouse move so that I can rotate the avatar to the mouse.

I have tried adding the evt listener in the init method of the avatar but it cannot access the stage at this point (presumably because the avatar has not been added yet).

Is there a function that I am missing?

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

Post by Bax »

What about listening to the AvatarEvent.AVATAR_CREATED event?
Check the API documentation for more informations about it.
Paolo Bax
The SmartFoxServer Team
clouting
Posts: 17
Joined: 18 May 2011, 13:57

Post by clouting »

Okay... but can I use this in the avatar class file (AvatarsContainer.fla)?
User avatar
Bax
Site Admin
Posts: 4626
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Post by Bax »

You can't listen to the event inside the avatar; you just have the init method, but as you pointed out, it is not enough.
The possible solution is to add a method to your avatar class and call it from outside when the avatar creation event is dispatched by OpenSpace.
Paolo Bax
The SmartFoxServer Team
clouting
Posts: 17
Joined: 18 May 2011, 13:57

Post by clouting »

Okay, Thanks...

I have managed to access my avatars function by using the following

Code: Select all

var avatarClass:Class = WorldVals.os.avatarAppDomain.getDefinition("FootballerAvatar") as Class;
var avatar:* = WorldVals.os.getMyAvatar() as avatarClass;
avatar.throwBalloon();
Is there a cleaner method of accessing the methods inside my avatar?

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

Post by Bax »

Why not the following simplified method?

Code: Select all

var avatar:FootballerAvatar = WorldVals.os.getMyAvatar() as FootballerAvatar; 
avatar.throwBalloon();
Paolo Bax
The SmartFoxServer Team
clouting
Posts: 17
Joined: 18 May 2011, 13:57

Post by clouting »

Surely I can't do that?

The avatar is in a separate .swf that has been loaded into its own ApplicationDomain.

Am I missing something obvious?
User avatar
Bax
Site Admin
Posts: 4626
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Post by Bax »

mmm.. actually you are probably right. The best way to know is.. try! :-D
If not working, then you have to use the method you wrote in a previous post.
Paolo Bax
The SmartFoxServer Team
Post Reply