/11/ movie clip subclasses (part 1)

function Ball (theColor) {
  this.setColor(theColor);
}


// The constructor takes no parameters. They are passed by
// attachMovie() and duplicateMovieClip().
function Ball () {
  // this.theColor is set by the attachMovie() initObj
  this.setColor(this.theColor);
}

// Set Ball superclass to MovieClip
Ball.prototype = new MovieClip();

// Associate the Ball class with a library symbol
Object.registerClass("ballSymbol", Ball);

// Create a few Ball methods
Ball.prototype.setColor = function (newColor) {
  var ballColor = new Color(this);
  ballColor.setRGB(newColor);
}

Ball.prototype.startMoving = function (moveAmount) {
  this.onEnterFrame = function () {
    this._x += moveAmount;
  }
}

Ball.prototype.stopMoving = function () {
  delete this.onEnterFrame;
}


// Make an instance. The Ball constructor is called automatically.
// The properties of our initObj (attachMovie()'s last argument) 
// are set on the redBall instance before the constructor runs.
this.attachMovie("ballSymbol", "redBall", 1, { theColor: 0xFF0000 });

// Call a method.
this.redBall.startMoving(5);
// this.redBall.stopMoving()