Using one class for multiple images

I’d like to add some variety to my particle engine by emitting a different image than the one that came before it. Because each image in the library requires its very own class, I’d can’t figure out an efficient way to grab a different image and assign my particle class to it.

I can’t use interfaces (too slow), can’t use wildcards/untyped objects (also too slow), and I can’t use external assets (must be packed into a single swf).

Any ideas?

You don’t need to actually create the class file for each image. In your emitter class simply choose from any variety of images in your library, referenced by their linkage name. The base class for each image is probably MovieClip or Bitmap, so work with that as your data type.

But last time I checked, I can’t use the base class as the data type–I have to use the image’s class itself.

For example, if I made an array that contained a bunch of different images/classes, I couldn’t loop through the array by identifying them by a base class:


var array:Array = new Array();
var image1:Symbol1 = new Symbol1();
array.push(image1);
var image2:Symbol2 = new Symbol2();
array.push(image2);

for (var i:int = 0; i < array.length; i++) {
  var image:MovieClip = array*;
  doSomething(image);
}

That doesn’t work. It’d have to be untyped or an Interface for it to work, which it isn’t an option for me.

EDIT: oh my god it does work. I don’t understand, because last time I checked (seriously) it didn’t. But I just wrote a quick test, I’m going to implement it in full and see what happens. Thanks for giving me a double-take Anogar, I appreciate it.