The codes written between the #initclip and #endinitclip in movieclip from a Flash file (Fla) library that has been attached somewhere in the same flash file by using the linkage id will be executed first before the codes in the first frame of that movieclip. But, this option is completely removed from AS3.

The exact place where it is useful is the user defined component. Component should have pre-defined classes before its been used somewhere. For default components we don't need this as they are already linked. But for user defined components we should use this to register the movieclip as component and initialize the component classes before its been used somewhere. Check the simple code. The following code is written in a movieclip which will be attached to the stage using the linkage id.

AS2:
trace("Normal Check");
#initclip
trace("Check");
#endinitclip
trace("Check Again");


When you run the file it will trace in the following order.

Check
Normal Check
Check Again

So, the code we have written between #initclip and #endinitclip excutes the codes first before the other codes written in the first frame.

What is the use of Object.registerClass?

This can be used in custom component creation to register a class to a movieclip that will be attached using the linkage id. See the code,

AS2: (inside a movieclip on first frame)
#initclip
function DrawRectangle() {
    this.setPosition(this.x, this.y);
    this.drawShape(this.width, this.height, this.colour);
}
DrawRectangle.prototype = new MovieClip();
DrawRectangle.prototype.setPosition = function(x, y) {
    this._x = x;
    this._y = y;
};
DrawRectangle.prototype.drawShape = function(width, height, colour) {
    this.beginFill(colour, 100);
    this.moveTo(0, 0);
    this.lineTo(0, height);
    this.lineTo(width, height);
    this.lineTo(width, 0);
    this.lineTo(0, 0);
    this.endFill();
};
Object.registerClass("myClip", DrawRectangle);
#endinitclip
venki
6/3/2012 08:14:55 pm

Hi arun,

while i am a beginer of as3, pls help me on the above code, how to convert this for as3?

thanks in advance..

Reply



Leave a Reply.