Hi all,
I’ve been working my way along with OOP and constructing objects.
I’ve done a simple script that bounces a mc around the stage.
[AS]function Person(myClip, x, y) {
this.myClip = myClip;
this.x = x;
this.y = y;
}
Person.prototype.update = function() {
this.myClip._x += this.x;
this.myClip._y += this.y;
};
Bouncer.prototype = new Person();
function Bouncer(myClip, x, y) {
super(myClip, x, y);
}
Bouncer.prototype.update = function() {
super.update();
this.bounceAtBorder();
};
Bouncer.prototype.bounceAtBorder = function() {
if (this.myClip._x>Stage.width-this.myClip._width/2) {
this.x *= -1;
}
if (this.myClip._y>Stage.height-this.myClip._width/2) {
this.y *= -1;
}
if (this.myClip._x<this.myClip._width/2) {
this.x *= -1;
}
if (this.myClip._y<this.myClip._width/2) {
this.y *= -1;
}
};
var motion = new Bouncer(cop1_mc, 5, 5);
cop1_mc.onEnterFrame = function() {
motion.update();
};[/AS]
My question is, is it possible to have the onEnterFrame call within the prototype, so when I call it I would just have
[AS]var motion = new Bouncer(cop1_mc, 5, 5);
motion.update();
[/AS]
I was trying something like this
[AS]
Person.prototype.update = function() {
this.myClip.onEnterFrame = fucntion(){
this.myClip._x += this.x;
this.myClip._y += this.y;
}
};
[/AS]