Avatar Creation in Flash

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

Moderators: Lapo, Bax

Nepaleno
Posts: 22
Joined: 06 May 2010, 06:28

Postby Nepaleno » 14 May 2010, 13:51

gl0om wrote:And what if I use DemoVatar class in my project? Compilator will stuck on line where the reference on DemoAvatar is.

The solution I used was getting DemoAvatar class definition from loaded swf file's application domain.

Code: Select all

private var DemoAvatar:Class;
private var myAvatar:*;

private function onAvatarSwfLoaded(evt:Event):void
{
   DemoAvatar = avatarAppDomain.getDefinition('DemoAvatar') as Class;
   myAvatar = openSpace.getMyAvatar() as DemoAvatar;
}

So every time I needed to use my DemoAvatar's methods I called them through myAvatar. But I'm sure there is simpler way to do this.
User avatar
Bax
Site Admin
Posts: 4612
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Postby Bax » 15 May 2010, 05:57

Another solution is that you declare myAvatarSymbol, avatarGraphics and what else in the DemoAvatar class, then open the actionscript properties panel of the DemoAvatarContainer.fla file and uncheck the Automatically declare stage instances flag.
In this way you should be able to compile the DemoAvatarContainer.fla and also reference the DemoAvatar class in your project.
Paolo Bax
The SmartFoxServer Team
gl0om
Posts: 54
Joined: 30 Mar 2010, 17:39

Postby gl0om » 20 May 2010, 12:09

bax wrote:Another solution is that you declare myAvatarSymbol, avatarGraphics and what else in the DemoAvatar class, then open the actionscript properties panel of the DemoAvatarContainer.fla file and uncheck the Automatically declare stage instances flag.
In this way you should be able to compile the DemoAvatarContainer.fla and also reference the DemoAvatar class in your project.


Well, this is exactly what I've done.

p.s.: I heard that you'll show us a new example with avatar soon. But when is it "soon"? I'm dreaming about this example :)
gl0om
Posts: 54
Joined: 30 Mar 2010, 17:39

Postby gl0om » 26 May 2010, 11:29

I'm trying to addChild from library in set skin function.
Object which I'm trying to add has MovieClip class and this class isn't changable. On adding attempt I receive message that object myst be of DisplayObject class. Why? Avatar class is child of MovieClip...
I can't understand how to work with skin object, how to add accessories to avatar, how to manage with it's state. Is there any examples or manuals about this?
User avatar
Bax
Site Admin
Posts: 4612
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Postby Bax » 26 May 2010, 11:45

What about checking the avatar example we provide? (ok, it is part of the OpenSpace Flex example, but the inner behavior of the avatar class -DemoAvatar.as- is always the same)
Paolo Bax
The SmartFoxServer Team
gl0om
Posts: 54
Joined: 30 Mar 2010, 17:39

Postby gl0om » 26 May 2010, 11:50

bax wrote:What about checking the avatar example we provide? (ok, it is part of the OpenSpace Flex example, but the inner behavior of the avatar class -DemoAvatar.as- is always the same)


Actually I work with your DemoAvatar.as from Flex example... Maybe I use old version of it, but there's no a single line about managing avatar's outlook.
User avatar
Bax
Site Admin
Posts: 4612
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Postby Bax » 27 May 2010, 07:27

gl0om wrote:Actually I work with your DemoAvatar.as from Flex example... Maybe I use old version of it, but there's no a single line about managing avatar's outlook.

If the swf file containing the avatars has the assets in it (which means movieclips in the library, with a linkage name assigned), then it is just a matter of adding a child to the displaylist. Can you please show the code not working?
Paolo Bax
The SmartFoxServer Team
gl0om
Posts: 54
Joined: 30 Mar 2010, 17:39

Postby gl0om » 27 May 2010, 17:16

Code: Select all

      override public function set skin(data:Object):void
      {
         trace("DemoAvatar: skin set to", data)
         _skin = data;
         
         if (_skin != null)
         {
            avatarGraphics.addChild(_skin.hat);
         }
      }
User avatar
Bax
Site Admin
Posts: 4612
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Postby Bax » 27 May 2010, 21:38

I suppose skin.hat contains a string, or a number. Why are you trying passing it to the addChild method? As you can read in the ActionScript documentation, the addChild method expects a DisplayObject to be passed.
So, assuming your avatars library contains a movieclip with its linkage name set to the skin.hat value (for example "panama"), then you should do something like this:

Code: Select all

var hatClass:Class = getDefinitionByName(skin.hat) as Class
var hatMC:MovieClip = new hatClass:Class() as MovieClip
avatarGraphics.addChild(hatMC)
Paolo Bax
The SmartFoxServer Team
gl0om
Posts: 54
Joined: 30 Mar 2010, 17:39

Postby gl0om » 27 May 2010, 21:55

oops :oops:
Indeed it was string in _skin.hat
I forgot that addChild requires DisplayObject and passed it's name... Sorry :roll:
gl0om
Posts: 54
Joined: 30 Mar 2010, 17:39

Postby gl0om » 29 May 2010, 09:15

Now I have such error:
ReferenceError: Error #1065: Variable panama is not defined

But, panama movieclip exists in DemoAvatarContainer.fla and it exported as panama. Is there any other place where I should define panama?
User avatar
Bax
Site Admin
Posts: 4612
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Postby Bax » 29 May 2010, 16:11

Interesting issue, glo0m... we didn't think about it when proposing the simplified SWC approach. The problem is this: the "panama" class is not referenced in your DemoAvatar class, so the compiler doesn't include it in the final SWF. So when you call the getDefinitionByName at runtime, Flash is not able to find the "panama" class. The simple solution is this: in your DemoAvatar class add something like this: var tmp:panama. This forces the compiler to include the "panama" class in the final SWF. The problem with this approach is that you have to reference ALL the avatar customization assets, which is not practical.
The best solution is to use the external SWF file loading approach.
We are now working on a full example showing avatar customization both in Flex and Flash, similar to the one we had in OpenSpace 1. We will make it available within a few days.
Paolo Bax
The SmartFoxServer Team
gl0om
Posts: 54
Joined: 30 Mar 2010, 17:39

Postby gl0om » 29 May 2010, 20:49

I suggest I didn't understand the solution you adviced, or it just doesn't work :?

I'm waiting for you example very much. I hope it'll set all my questions.
User avatar
Bax
Site Admin
Posts: 4612
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Postby Bax » 08 Jun 2010, 19:53

OpenSpace 2.0.1 has been released. It contains a full Flash example.
Paolo Bax
The SmartFoxServer Team

Return to “OpenSpace v2 discussions and help”

Who is online

Users browsing this forum: No registered users and 40 guests