Tag Archives: prototype

Object.prototype Crap

Actionscript:
  1. Object.prototype.myVar = "I am a variable";
  2.  
  3. var s:Sprite = new Sprite();
  4.  
  5. trace(Object(s).myVar);
  6.  
  7. var v:Video = new Video();
  8. trace(Object(v).myVar);

This.... should not be done... and setting myVar like this:

Actionscript:
  1. Object(s).myVar = "hello";

Will cause an error....

I keep a folder on my laptop for this website..... when I have a random snippet idea I put it in this folder.... Every couple of weeks I go through this folder and turn select snippets into posts.... when I rediscovered this snippet today it really made me laugh....

Posted in Object, dynamic | Also tagged , | Leave a comment

MovieClip.prototype

Actionscript:
  1. MovieClip.prototype.tint = function(col:uint):void {
  2.     var ct:ColorTransform = transform.colorTransform;
  3.     ct.color = col;
  4.     this.transform.colorTransform = ct;
  5. }
  6.  
  7. var circle:MovieClip = MovieClip(addChild(new MovieClip()));
  8. with (circle.graphics) {
  9.     beginFill(0x123455);
  10.     drawCircle(0,0,50);
  11.     x = 100;
  12.     y = 100;
  13. }
  14.  
  15. circle.tint(0xFF0000);

When AS3 first came out I didn't realize that prototype was still around.... This adds a function called tint() to all MovieClips. You should extend MovieClip instead of using this method.... but it's interesting to see that it's still around. There's an explanation of prototype and the AS3 namespace here.

Posted in MovieClip, color | Also tagged , , | Leave a comment