PDA

View Full Version : Syntactic Sugar for moving MCs.


Sammo
12-19-2006, 02:03 PM
MovieClip.prototype.move = function(direction, speed) {
switch (direction) {
case "up":
this._y -= speed;
break;
case "right":
this._x += speed;
break;
case "down":
this._y += speed;
break;
case "left":
this._x -= speed;
break;
}
}

// allows:
hero_mc.move("left", 5);

Just to make your code that bit more readable and DRY.

Templarian
12-20-2006, 12:08 AM
...hmm... simple but some of the newbies might like this.

For simple explanation (just if anyone searchs and finds your thread):
http://www.kirupa.com/developer/actionscript/tricks/prototypes.htm