I'm designing a small game and I'm creating a class for a mob object. The class contains some broad variables that will be useful in creating multiple instances of this object. I was wondering if it would be ok to have a loader inside the class instead of a loader in the main class that could be used to load images for the mob class I'm writing.
Is this an ok practice? I've seen some posts about having multiple loaders, and this would kind of be like that, but none of the posts seemed to mention what would be most efficient. I've done this before in other projects, but don't have any benchmarks or anything.
So can anyone tell me if this isn't too resource intensive to have each instantiation use it's own loader, then set it to null after the image is loaded? The scope of the project is pretty basic, but it'll be nice to know for future projects.
--edit--
I just looked into graphics.copyfrom(source) and realized that isn't going to work. Even more research brought me to a surprising lack of "movieclip cloning". Also, as I feared, pointing multiple movieclips to the loader content removed all of them when I tried to remove one.
Sadly even though my original choice may not be efficient, it's basically the only way this can be done... Each mob has an animated swf movieclip, so I can't make bitmaps. I also can't reuse the content from loaders because if multiple movieclips point to it, altering one mob will cause changes in the movieclips of the rest. Unfortunately, I'm going to - for now - stick to each mob having it's own loader (that is set to null after being used) and loading an external swf. Apparently there used to be a way to do this in AS2, and I don't want to use library symbol with document classes. So, I'm stuck. Thanks for the help I guess, please post back if you figure out a solution for my problem!
--edit--
I figured a code snippet might also be useful. Keep in mind these are swfs with 20+ frames being loaded.
public class Spawner {
var mc:MovieClip;
var loader:Loader;
var refr:Stage;
var x:Number,y:Number;
var loaded:Boolean = false;
public function Spawner(ref:Stage, type:String, inx:Number, iny:Number) {
refr = ref;
x = inx;
y = iny;
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadImg);
loader.load(new URLRequest(type));
}//constructor
public function loadImg(e:Event):void{
mc = MovieClip(e.target.content);
loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, loadImg);
refr.addChild(mc);
mc.gotoAndStop(1);
mc.x = x;
mc.y = y;
refr = null;
loader = null;
loaded = true;
}//loadImg
}//class