Reusing animations in flash

168 views Asked by At

Ok, I'm new to flash, so this is sort of a how to question, and sort of a best practices question.

I'm trying to make a game where the user has a board full of tiles, similar to memory. I made one tile, it looks good, and I put a motion tween on it.

  1. Frame 1 has stop();
  2. Frame 2->X has a motion tween
  3. Frame X emits a custom event

Then on the stage:

  1. mc.gotoAndPlay(2);
  2. addEventListener(mc, "my_custom_event");
  3. handle the event, knowing the animation is finished

So I can add many more complicated animations on the symbol's timeline, and call gotoAndPlay(57), gotoAndPlay(104), etc., each time triggering a different animation.

My problem is that I need to add lots of new tiles, dozens of them. The only thing that changes from tile to tile is the image I'm using; the animations are exactly the same, just a different bitmap(all the same size). So what I'd like to avoid is having 50 different movie clips and adding all the animations and event code to each one.

I had thought of putting an empty container on the symbol, and tweening that. I was going to add the proper graphic to the container on frame 1. But the symbol itself is empty at design time, so at every keyframe it goes back to empty.

What's a good way to accomplish this?

Thanks for any advice!

1

There are 1 answers

0
www0z0k On

if you have an animated blank rectangular sprite on the stage of an swf (and it's the only child there) you may load it into the main app using the Loader class and then use (Loader.content as Sprite).getChildAt(0).graphics.beginBitmapFill(/*your tile bitmap*/) to convert it to the tile you need