-
Hi there!!!
this works well when published with Flash 5 but not with Flash MX, any one knows how to fix this and keep it compatible, or how to do the same but in MX style?
//
MovieClip.prototype.randomizer = function(ancho,alto) {
this.nextX = Math.round(Math.random()*ancho);
this.nextY = Math.round(Math.random()*alto);
}
//
MovieClip.prototype.goInertia = function(nextX,nextY,vel) {
this._x += ( nextX - this._x ) / vel ;
this._y += ( nextY - this._y ) / vel ;
if (this.hitTest(nextX, nextY)) {
randomizer(ancho,alto);
}
}
//
and on mc:
onClipEvent (load) {
ancho=450;
alto=250;
// randomizer = stage size _x and _y
randomizer(ancho,alto);
}
onClipEvent (enterFrame) {
goInertia(nextX, nextY, 10);
}
is weird, other prototypes work well, like this one:
//
MovieClip.prototype.LookAt=function (x,y){
Xdiff = x-this._x;
Ydiff = y-this._y;
radAngle = Math.atan2(Ydiff, Xdiff);
this._rotation = radAngle*360/(2*Math.PI);
}
//
onClipEvent (enterFrame) {
LookAt(_parent.something._x, _parent.something._y);
}
any help is apreciated.
-
The problem is in the way that Flash MX resolves variable references.
So, change goInertia to:
Code:
MovieClip.prototype.goInertia = function(nextX,nextY,vel) {
this._x += ( nextX - this._x ) / vel ;
this._y += ( nextY - this._y ) / vel ;
if (this.hitTest(nextX,nextY,true)) {
this.randomizer(this.ancho,this.alto);
}
}
// or, more convenient
MovieClip.prototype.goInertia = function(nextX, nextY, vel) {
with (this) {
_x += (nextX-_x)/vel;
_y += (nextY-_y)/vel;
if (hitTest(nextX, nextY, true)) {
randomizer(ancho, alto);
}
}
};
and everything will be ok.
- n.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|