A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: [as3] How to replace a character movie clip with another one?

  1. #1
    Registered User
    Join Date
    Jul 2013
    Posts
    2

    [as3] How to replace a character movie clip with another one?

    The idea for my game is this: the main character runs around the screen and there's other AI characters walking around. He walks up to one and presses "enter" and then an animation of him strangling that AI character begins.

    Since the AI characters are going to look different from each other (e.g. male female, different hair color, etc.), does this mean you have to make a new strangling animation for EACH AI character, or can you create ONE strangling animation with a generic, blank character movieclip, and (then using code) replace that movieclip with the proper AI movieclip?

    Thanks.

  2. #2
    When you know are. Son of Bryce's Avatar
    Join Date
    Aug 2002
    Location
    Los Angeles
    Posts
    838
    The description makes me laugh, haha!

    You could do it both ways. It's probably easier to do it as separate movieclips for each character, but more tedious work. It's probably more reasonable to do one animation, and switch the art within each of the body parts.

    So for instance a walk animation timeline would have 2 arms, a head, a body, 2 legs, etc. You can animate along that timeline. The first frame of the animation, or the code telling the animation to play, would tell each body part to gotoAndStop() at a different frame.

    Each one of those body parts would stop on the first frame, but have several frames with different art. So the head would have 5 frames, with 5 different heads. By giving each movieclip an instance name, you can target that movieclip and tell it which frame to go to.

    Then the code would be something like this for enemy #3.

    Code:
    head.gotoAndStop(3);
    body.gotoAndStop(3);
    leftArm.gotoAndStop(3);
    rightArm.gotoAndStop(3);
    //etc.
    The movieclip should stay the same as it moves along the timeline and through keyframes, but it will revert back to the first frame if you switch movieclips (like if you have 2 hands, one closed and one open). You'll have to call that code each time the movieclip changes.

    In that case, it's probably better for the movieclip itself to check on the first frame. It could check to see which enemy it is from its parent, and switch to the correct frame.

    Code:
    // inside of the arm movieclip with 5 frames
    int myNum = MovieClip(parent).enemyNum;
    gotoAndStop(myNum);
    Something like that. Both of these solutions seem kinda hacky to me, but if you fiddle with them you'll eventually get it to work. That's what Flash is all about! haha

  3. #3
    Registered User
    Join Date
    Jul 2013
    Posts
    2
    I'll try that out, thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center