Random movement idea / question

Ok I need some major help do to my major lacking in actionscripting.
:upset:

I want to have a MC that is going to work as a button.

ok, now having said that…I want it to be constantly moving in (doing a little jitter) in a confined space lets say a 65px by 65px space. BUT when some one puts there mouse over the MC I want it to stop moving (jittering) and play forward its rollover animation.

Currently I have this set on the button


onClipEvent(enterFrame){
        if (this.hitTest(_root._xmouse, _root._ymouse, true)){
                this.nextFrame();
        } else {
                this.prevFrame();
        }
}

Obviously this is to play the animation forward when a mouse is over top. (Don’t get me wrong, I didn’t figure that out by myself) :blush:

What would I add for the motion. It can be actually random…or it can be fixed…(i would rather it be random)

Ideally I would also like to have the MC follow the mouse pointer until it leaves the 65px by 65px square, and then go back to moving (jittering)

Case

Ok I now have updated my button.

After scouring for hours and hours I found a simple tutorial on this great site. :azn:

Called Vibration Effect by kirupa and superbeener.

With a slight modification I suited it to my needs. (mostly deleting :P)

So without further waiting here is my updated AS on my MC’s


onClipEvent (load) {
	//setting initial coords
	cx = 213;
	cy = 150;
}

onClipEvent(enterFrame){
        if (this.hitTest(_root._xmouse, _root._ymouse, true)){
                this.nextFrame();
        } else {
                this.prevFrame();
        }
		this._x = cx+(1+Math.random()*5);
	        this._y = cy+(1+Math.random()*5);
}

Now my question is this how to I get it to stop vibrating on the rollover. And when someone is pulling there mouse away, It should follow for about 10px and bounce back to it’s initial position and continue it’s dance.

Thanks,
Case :rambo:

p.s. There is a spelling error on the Vibration Effect tutorial (A common one. :jag: )

Ok,

Making headway here…

I did some more fiddling around and got this that works


onClipEvent (load) {
	//setting initial coords
	basex = this._x
	basey  = this._y
	cx = this._x;
	cy = this._y;
}

onClipEvent(enterFrame){
        if (this.hitTest(_root._xmouse, _root._ymouse, true)){
				this._x = basex;
				this._y = basey;
                this.nextFrame();
        } else {
                this._x = cx+(1+Math.random()*5);
			    this._y = cy+(1+Math.random()*5);
				this.prevFrame();
        }
}


Now I have it working so that it vibrates, and stops when the hit test is true (or the mouse is over it).

Ok, now I am on to the elastic-type effect, to which I searched the forums for but found no answer to my dilemma.

Thanks as usual to all onlookers,

Case