flash on mouse move???
- Started
- Last post
- 5 Responses
- wwfc
Hi All, I'm trying to figure something out here - but am strugglin more then a little!
I have this script:
// custom variables
graphic.elasticity = 20;
graphic.resistance = .1;
// internal variables
graphic._xvelocity = 200;
graphic._yvelocity = 200;
function followMouse(){
this._x = this._parent._xmouse;
this._y = this._parent._ymouse;
}
function springToOrigin(){
this._xvelocity -= this._x * this.elasticity;
this._yvelocity -= this._y * this.elasticity;
this._xvelocity *= this.resistance;
this._yvelocity *= this.resistance;
this._x += this._xvelocity ;
this._y += this._yvelocity ;
}
area.onRollOver = function(){
this._parent.swapDepths( _root.getNextHighestDepth() );
graphic.onEnterFrame = followMouse;
graphic.gotoAndStop(2);
}
area.onPress = function(){
graphic.onEnterFrame = springToOrigin;
graphic.gotoAndStop(1);
}works great and makes the movieclip attach to the mouse then spring to origin fine - but what I am struggling with is making the spring to origin action trigger when the mouse moves even a little - I tried adding this:
onMouseMove = function () {
graphic.onEnterFrame = springToOrigin;
graphic.gotoAndStop(1);
}but it doesn't work and has quite the opposite effect - and the movieclip stays attached and acts as a custom cursor!!!
How do I add some code to recognise the mouse movement and then spring to origin when the mouse moves?
Ideally I would add the mousemove code to the existing code or movieclip as there are a number of said clips in the fla and they need to function independently?
Anyone see the wood with all those trees???
**crosses fingers and hopes for the best
- Jimbo820
Wycombe Wanderers?
- Mishga0
Ok i not sure if this is the effect the want to use, so far i have:
[Code]
area.onRollOver = function() {
graphic.onEnterFrame = function() {
var xMouse = _root._xmouse;
var yMouse = _root._ymouse;
if (Math.abs(xMouse-this._x)<1) {
this._x = xMouse;
this._y = yMouse;
} else {
this._x -= (this._x-xMouse)/6;
this._y -= (this._y-yMouse)/6;
}
};
};
area.onRollOut = function() {
graphic._x = 20;
graphic._y = 20;
delete graphic.onEnterFrame;
};[end code]
i can't manage to make the rollout effect with easing..sorry.:P
this is the tutorial i checked..
http://www.spoono.com/flash/tuto…Cheers..Hope someone else help you..=)
- wwfc0
...cheers Mishga
- Mishga0
Got it! =)
When i rollover the button, the graphic follows the mouse, when i rollout the graphic goes to the coordinates I'll tell to go:[CODE]
area.onRollOver = function() {
graphic.onEnterFrame = function() {
var xMouse = _root._xmouse;
var yMouse = _root._ymouse;
if (Math.abs(xMouse-this._x)<1) {
this._x = xMouse;
this._y = yMouse;
} else {
this._x -= (this._x-xMouse)/6;
this._y -= (this._y-yMouse)/6;
}
};
};
area.onRollOut = function() {delete graphic.onEnterFrame;
graphic.onEnterFrame = function() {
var xOrigin = 20;
var yOrigin = 20;
if (Math.abs(xMouse-this._x)>1) {
this._x = xOrigin;
this._y = yOrigin;
delete graphic.onEnterFrame;} else {
this._x -= (this._x-xOrigin)/6;
this._y -= (this._y-yOrigin)/6;
}
};};
[End CODE]
- Mishga0
Spring effect:
http://www.sitepoint.com/article…Cheers!=)