Flash AS crit
- Started
- Last post
- 4 Responses
- vaporstouch
Just starting to write custom functions in external .as files, and after working through some tutorials i have this simple one for moving MCs. Would you take a look and tell me if there is anyway to improve/streamline the code? Thanks
//move MC to x / y cordinates//
function moveMyMc(clip, moveX, moveY, myEase) {
clip.onEnterFrame = function() {
if ((Math.Abs(moveX-clip._x)(lessth... && (Math.Abs(moveY-clip._y)(lesstha... {
this._x = moveX;
this._y = moveY;
delete (this.onEnterFrame);
} else {
clip._x -= (clip._x-moveX)*myEase;
clip._y -= (clip._y-moveY)*myEase;
}
}
}
- stewart0
you better post a .fla file or the .as, because the lessthan etc is shite.
- nospacebar0
Looks good.
- Anarchitect0
don't use onClip events. use intervals, you can override the framerate by changing its loop speed.
MovieClip.prototype.slidePos(mov... moveY, myEase) {
if ((Math.Abs(moveX-this._x) { 1) && (Math.Abs(moveY-this._y){1)) {
this._x = moveX;
this._y = moveY;
clearInterval(slideLoop);
} else {
this._x -= (this._x-moveX)*myEase;
this._y -= (this._y-moveY)*myEase;
}
}
}//30 is the interval in milliseconds, the bigger it is, the slower is the interval
MovieClip.prototype.slide(moveX, moveY, myEase){
clearInterval(this.slideLoop);
this.slideLoop=setInterval(this... moveX, moveY, myEase);
}//you can now use this in any MC with
// mc.slide(10,20,0.5);
- vaporstouch0
Thanks for the replies, and especially for the advice/code, Anarchitect!