all groups > flash actionscript > september 2005 >
You're in the

flash actionscript

group:

Flash 8 MovieClip.prototype function doesnt work


Flash 8 MovieClip.prototype function doesnt work poket
9/20/2005 9:07:45 PM
flash actionscript:
I had this code that I've used a million times for motion set as a movieclip
function.

MovieClip.prototype.moveit = function (centerx, centery, inertia, k) {
//trace(centerx+","+ centery+","+ inertia+","+ k)
this.x = -this._x+centerx;
this.y = -this._y+centery;
this.xp = this.xp*inertia+this.x*k;
this.yp = this.yp*inertia+this.y*k;
this._x += this.xp;
this._y += this.yp;
};

Pretty basic really. I have a movie clip that calls the moveit function from
an onClipEvent(enterFrame) event. If I publish as flash 6 it works fine, as
soon as I change it to flash 8 it doesnt work. I know the function is getting
called because I can trace the parameters, but it doesnt have the desired
effect. Any help would be greatly appreciated.

Thanks,
Jason
Re: Flash 8 MovieClip.prototype function doesnt work taraschuk
9/20/2005 9:11:41 PM
Jason --

Re: Flash 8 MovieClip.prototype function doesnt work poket
9/20/2005 9:23:00 PM
Re: Flash 8 MovieClip.prototype function doesnt work Jeckyl
9/21/2005 12:00:00 AM
taraschuk: unless publishing for AS2 there is no need (and no way) to derive
from MovieClip class other than the good-old prototype way

And regardless .. the prototype worked because the tracing happened
(according to the OP) .. so the movie method is available and being called.

Problem is most likely that you never initialised the this.xp and this.yp
.... if you don't init for Flash 7 or later, then the value is undefined, and
for FP7/8 arithmetic with undefined gives you undefined value, whereas in
FP6 or earlier undefined gets treated as zero.

So...

this.xp = this.xp*inertia+this.x*k;
this.yp = this.yp*inertia+this.y*k;

will result in this.xp and this.yp being undefined .. in FP6 or earlier,
you'd get an actual value.
--
Jeckyl

AddThis Social Bookmark Button