0

I have a character with different body parts: Hair, Head, Body, Arms, Legs. I animated the character with a walk animation and stand animation. I have given the character's hair an instance name of hair in each of these animations so I can access it through AS3. Let's say I have a different movieclip that is a static image of a different type of hair. I want to be able to change the character's hair to that hair using AS3.

instances: model = animation movieclip within holder movieclip. hair = children of model, but is animated

Classes: Anim = holder movieclip (for changing reference point and resizing) Hair2 I want to change hair to an instance of Hair2

anim.model.hair = new Hair2();

When I trace it it shows the object has been changed but it's not changed on display. I'm using AS3IsoLib so here's an example code:

var anim = new Anim();
var hair2 = new Hair2();
anim.model.hair = hair2;
sprites = [anim];

I tested scaling the hair and that works fine but not replacing the instance itself.

I was wondering how I can accomplish this. If you played some MMO games, the user has the option of modifying his or her body parts. An example will be Adventure Quest Worlds. That is the effect I want to accomplish.

1 Answers1

0

The AS2 syntax is quite confusing: setting anim.model.hair means nothing actually. Here's how you should write it:

//keep a reference for the previous hair
var previousHair:MovieClip = anim.model.hair;
//copy position, rotation, scale
hair2.transform.matrix = previousHair.transform.matrix.clone(); 
//remove the previous hair from model
anim.model.removeChild(previousHair);
//put the new hair in place
anim.model.addChild(hair2);
//give a new instance name to hair2 so you can access it through anim.model.hair
hair2.name = "hair";
Kodiak
  • 5,978
  • 17
  • 35
  • That would work if hair2 was a child already of the animation which I named the instance model. However, it doesn't work if I create an instance of the hair2 class that has no link to the animation besides being an entirely separate movieclip. –  Apr 24 '12 at 12:53
  • What happens then? What is missing? What is expected? – Kodiak Apr 24 '12 at 13:46
  • I agree. This solution should work in the general case. If it is not doing the trick, you may need to post more code. It sounds like `hair1` may be loaded twice, if `hair1` is still there; or if `hair2` is not appearing, it may not be visible, it may be an empty MovieClip, it may be positioned incorrectly, etc. – iND Apr 25 '12 at 03:52