Hello :)
the __proto__ solution is a good solution :
/**
* Constructor of the class
*/
function Square()
{
this.draw() ;
}
/**
* Square extends MovieClip
*/
Square.prototype.__proto__ = MovieClip.prototype ;
/**
* Draw the square shape.
*/
Square.prototype.draw = function()
{
this.beginFill(0xFFFFFF, 100) ;
this.lineTo(100,0) ;
this.lineTo(100,100) ;
this.lineTo(0,0) ;
this.lineTo(0,0) ;
this.endFill() ;
}
/**
* Sets the color of the movieclip.
*/
Square.prototype.setRGB = function ( color:Number )
{
(new Color(this)).setRGB(color) ;
}
// test attachMovie
var mc1:MovieClip = attachMovie("myID", "myClip", 1) ;
mc1.__proto__ = Square.prototype ; // change the prototype reference
Square.call(mc2) ; // launch the constructor of the Square class
mc1.setRGB(0xFF0000) ; // ok
// test with createEmptyMovieClip
var mc2:MovieClip = createEmptyMovieClip("myClip2", 2) ;
mc2.__proto__ = Square.prototype ; // change the prototype reference
Square.call(mc2) ; // launch the constructor of the Square class
mc2.setRGB(0xFF0000) ; // ok
@Yehia Shouman : your delete in your "changeColorTo" method is useless
because all local variables with a var in a method is remove by the Garbage
collector at the end of the call function.
EKA+ :)
2006/12/1, Yehia Shouman <[EMAIL PROTECTED]>:
function Square(){}
Square.prototype=new MovieClip();
Square.prototype.changeColorTo=function (clr:Number)
{
var tempClr:Color=new Color(this);
tempClr.setRGB(clr);
delete tempClr;
}
var linkageID_str:String="exportedClip";
//associate the linked clip with sub class
Object.registerClass(linkageID_str,Square);
//attach
var mc:MovieClip= attachMovie(linkageID_str,"mc",1);
//then prohibit further association of linked clip to class
Object.registerClass(linkageID_str,null);
//when you call the method it should work
mc.changeColorTo(0xFF0000);
Same idea if you're working with Actionscript 2.0
Y Shouman
On 12/1/06, Micky Hulse <[EMAIL PROTECTED]> wrote:
>
> Just curious if it is possible to extend/apply a sub class to a swf
> which is loaded via attachMovie()?
>
> TIA,
> Cheers,
> M
>
> --
> Wishlist: <http://snipurl.com/vrs9>
> Switch: <http://browsehappy.com/>
> BCC?: <http://snipurl.com/w6f8>
> My: <http://del.icio.us/mhulse>
> _______________________________________________
> [email protected]
> To change your subscription options or search the archive:
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
> Brought to you by Fig Leaf Software
> Premier Authorized Adobe Consulting and Training
> http://www.figleaf.com
> http://training.figleaf.com
>
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com