PDA

View Full Version : Elasticity Prototype for Flash 8 Users



DV81
November 20th, 2006, 01:04 AM
Hey guys just thought i'de share something I learnt today !
It uses _xmouse and _ymouse but can be adapted to your OWN targets for X and Y just
let me know if you need a hand, once again i know it's not much but just was in a giving mood ! thanks guys

Bass



// ELASTICITY PROTOTYPE
// Created on the 20th Nov 2006 by DV81
//
// This can be extended further but made it for people who don't want
// to use the tween classes and want raw math for more control.
// Note also I know there are 1 million ways to skinning a cat, but I spent almost all
// day trying to figure this out to work with Flash 8 who knows might come
// in handy for someone. Enjoy!

MovieClip.prototype.elastic = function(accel, friction) {
this.dX = 0;
this.dY = 0;
this.onEnterFrame = function(){
this.dX = (this.dX * friction)+((_xmouse - this._x) * accel);
this.dY = (this.dY * friction)+((_ymouse - this._y) * accel);
this._x += this.dX;
this._y += this.dY;

// This is added to save resources you can delete or comment out if you
// need continuous movement.
if(Math.abs(this.dX) < 0.01 || Math.abs(this.dY) < 0.01){
delete this.onEnterFrame;
}
//
}
}

// USAGE
// Simply create a movieclip dynamically or manually then call 'elastic' function
mc.elastic(0.1,0.9);

Icy Penguin
November 20th, 2006, 01:37 AM
Hey, that's pretty cool!
Nice work!

Thanksies! :)

antongranik
November 20th, 2006, 03:08 AM
Great! Thanks a lot! Like it!

DV81
November 20th, 2006, 05:21 AM
welcome guys ! glad you like it :)

ag0609
November 28th, 2006, 11:03 PM
Checked compatibility of this prototype:

----------------------------------------------------
Flash 8 AS 2: OK, AS 1: OK
Flash 7 AS 2: OK, AS 1: OK
Flash 6 AS 2: OK, AS 1: OK

Prototype only support least Flash 6
----------------------------------------------------