Page 1 of 1

Avatar added to stage

Posted: 07 Jul 2011, 09:49
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

Posted: 07 Jul 2011, 11:02
by Bax
What about listening to the AvatarEvent.AVATAR_CREATED event?
Check the API documentation for more informations about it.

Posted: 07 Jul 2011, 11:48
by clouting
Okay... but can I use this in the avatar class file (AvatarsContainer.fla)?

Posted: 08 Jul 2011, 08:02
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.

Posted: 08 Jul 2011, 08:38
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

Posted: 08 Jul 2011, 08:46
by Bax
Why not the following simplified method?

Code: Select all

var avatar:FootballerAvatar = WorldVals.os.getMyAvatar() as FootballerAvatar; 
avatar.throwBalloon();

Posted: 08 Jul 2011, 12:33
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?

Posted: 10 Jul 2011, 12:41
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.