I am a very comfortable AS3 coder, but have been tasked with maintaining a very large, in production, ball of mudish AS2 application. its exchanged so many hands no one exists who knows how it works :P.
I’ve come across this series of logic and I don’t understand exactly what its doing, and I was hoping for some help. Heres the example:
public function createClip($theClass:Function, $name:String, $init:Object, $depth:Number):MovieClip {
var saveProto:Object = MovieClip.prototype;
MovieClip.prototype = $theClass.prototype;
var mc:MovieClip = this.createEmptyMovieClip($name, $depth);
MovieClip.prototype = saveProto;
mc.initProps = $init;
Function($theClass).call(mc, true);
return mc;
}
Ill tell you what I understand. The saveProto var is used to store the current prototype of Movieclip. The MovieClip prototype is changed to the passed in class prototype. A new Movieclip is created (mc). The old prototype is restored. initProps are set in mc.
Then as far as I can tell this line:
Function($theClass).call(mc, true);
calls the constructor of $theClass (as far as I can see with the CS4 Debugger). This kind tripped me up but I believe if I’m understanding right, the constructor is being called as if mc is calling it, and is being passed true. In a specific instance I was watching in the debugger, the constructor had no parameters… but AS2 seems to not care that much about that.
What i’m mainly confused with is the
MovieClip.prototype = $theClass.prototype;
var mc:MovieClip = this.createEmptyMovieClip($name, $depth);
MovieClip.prototype = saveProto;
It seems like that if the prototype is reset after… then its not going to matter. That new MovieClip will have the old prototype anyway… since its being reset… Why would this code be this way? Is it meaningful? Am I not understanding this quite right?
Sorry but I had trouble phrasing a question for google on this, my research turned up nothing
Thanks for any help in advance.