Posted By

Bonky on 06/08/07


Tagged

class movieclip attachMovie


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

hi2shamika20
re0gi04sser08


Create MovieClip With Custom Class


 / Published in: ActionScript
 

URL: http://mabblog.com/blog/?p=170

Use like this:

createClassMovieClip(CustomClass, “newclip”, getNextHighestDepth(), {x:10, _y:10, something:function(){this.something = 10;}})

  1. /*
  2.  Description: A function used for creating empty movie clips with subclass association.
  3.  
  4.  Parameters:
  5.  c:Function - The class to associate with the the empty movie clip.
  6.  name:String - The instance name for the empty movie clip.
  7.  depth:Number - The depth for the empty movie clip.
  8.  initOb:Object - Optional, object to copy properties from
  9.  
  10.  Returns:
  11.  MovieClip - A reference to the newly created movie clip.
  12.  */
  13. MovieClip.prototype.createClassMovieClip = function(c:Function, name:String, depth:Number, initOb:Object) : MovieClip {
  14. var mc:MovieClip = this.createEmptyMovieClip(name, depth);
  15. mc.__proto__ = c.prototype;
  16. mc.constructor = c;
  17.  
  18. if(initOb) {
  19. for(var prop in initOb) {
  20. mc[prop] = initOb[prop];
  21. }
  22. }
  23.  
  24. c.call(mc);
  25. return mc;
  26. }

Report this snippet  

You need to login to post a comment.