Dynamically changing timeline instances from AS3

Hello everyone,

Synopsis :
I’m currently working on (sort of) a fighting game in AS3.
-I’m using the FlashDevelop IDE.
-Graphical resources are drawn using the Flash IDE and saved in a .SWC file, which is imported in the FD project (of course, all needed MovieClips are marked to be exported for Actionscript).
-Character movement is not controlled by the keyboard; the user chooses the next action he takes, and then the result animation is played. Much like a rock-paper-scissors game, but with multiple choices.

All the character animations are contained in an “ActorPose” MovieClip. On the timeline of this movieclip, I’ve went ahead and animated all of the currently needed actions. So in my project, if I write something like this :


var actor:ActorPose = new ActorPose();
actor.gotoAndPlay("basic_attack");

after this finishes, the actor receives a gotoAndPlay(“stance”) which keeps the actor in a stance looping animation, waiting for other commands.

**The Problem :
**I have coded and animated everything, keeping in mind that I want to customize the appearance of the characters. So my ActorPose contains movie clips that have the same instance name throughout the whole timeline. So if ActorPose contains a MovieClip with the instance name “head”, head has 10 frames and is set to stop() in the first frame, I can easily write this in my code :


var actor:ActorPose = new ActorPose();
actor.head.gotoAndStop(4); // displays graphics in frame 4 of the head movieclip
actor.torso.gotoAndStop(2); // same thing for the torso
actor.arm.gotoAndStop(3); // and another example
actor.gotoAndPlay("basic_attack");

This works fine, and the proper frame is displayed. However, after frame 25 of the ActorPose timeline, all of the movieclips seem to reset to their initial state. I have thoroughly checked that the same instance name / movie clip source is used on the whole timeline of ActorPose, so that’s not the problem. I tried to detect any frame changes in the “head” instance using the FD debugger. Indeed, in some frames, the instance of “head” is null, although it exists on that frame in the timeline, and has the correct instance name.

Could it be that Flash detects that I “backtracked” during my animation? For instance, I copied all of the body parts from frame 30 to frame 25 (but keeping the same instance names). So then it considers that those are not the same movie clip instances as in frame 1-24. I tried to remake those problematic frames (ones in which clips seem to reset), by copying the instances from previous keyframes (so actually remaking the whole animation). This seems to work, the MovieClips “reset” later on, in frames that I haven’t remade. However, this is a real pain, as there is no way to see this problem while making the actual frame-by-frame animation. So this whole workflow would be faulty and time wasting.

Is there anyone that encountered such problems? And if not, how would you handle this problem :

  • Make complex character animations and still have the possibility of changing MovieClip appearance at runtime.

*Note:
I agree that maybe changing the appearance of a movieclip by gotoAndStop(someOtherFrame) is not the best solution. But I also tried this by swapping the movieclip with another, same behavior occurs. Something like :


var newAppearance:MovieClip = new Head2();
actor.head.removeChildAt(0);
actor.head.addChild(newAppearance);

produces the same result, head resets to initial state at the problematic frames.

If you had any experience with this, please share. Maybe my workflow is faulty and there is another safe way of doing this, without encountering these problems.
Animating using AS3 code is not an option. I see no way to replicate frame-by-frame animation quality by using a Tweener or such.
Any feedback is highly appreciated, as I am stuck at this point, not knowing if it is worth advancing in this manner or not.
Thank You!