views:

25

answers:

1

I got this ActionScript 2 code:

fuseModel = [{mx:0, my:-5.5, x:0, y:-4, pen:.5, clr:0x000033, alpha:50}];

MovieClip.prototype.setModel = function(m)
{
 this.drawModel(m);
}

MovieClip.prototype.drawModel = function(m)
{
 var pt = m[0];
 beginFill(pt.bf, pt.bfa);
 lineStyle(pt.pen,pt.clr,pt.alpha);
 lineTo(100,100);
 endFill();
}

_root.createEmptyMovieClip("ship_mc", 2);
ship_mc.setModel(fuseModel);

This code is just drawing a line (I deleted the other 600 lines of code for simplicity).

I'm trying to understand where the MovieClip.prototype.setModel method is called. Looks like nowehere, but, if I delete it, the line is not drawn.

So, who is calling MovieClip.prototype.setModel()?

--update

looks like the ship_mc.setModel(fuseModel) is calling it, so for every instance of MovieClip the setModel will exist? It doesn't make sense as it is not in MovieClip, but in MovieClip.prototype.

+1  A: 

In ActionScript 2 (and ActionScript 1 and JavaScript) you can add methods to an objects prototype, and all objects of that type, that class, will then have that method. You can kind of think of the prototype as the class definition, so in your code, defining MovieClip.prototype.setModel and MovieClip.prototype.drawModel is like adding methods to the MovieClip class.

Lars