On (release); Please Stop Mc! Urgent!

Hey Everybody,
I need to create a btn that disable the following code:

 
onMouseMove = function () {
 i++;
 distX = iniX-_xmouse;
 distY = iniY-_ymouse;
 distTotal = Math.sqrt(distX*distX+distY*distY);
 if (distTotal>dist) {
  iniX = _xmouse;
  iniY = _ymouse;
  np = attachMovie("p", "p"+i, i);
  np._xscale = np._yscale=Math.random()*150+50;
  np.ang = Math.random()*360;
  np.velX = .1;
  np.velY = .1;
  np._x = _xmouse;
  np._y = _ymouse;
  np.onEnterFrame = move;
 }
};

Can anyone please help???

Tks!!!

my_btn.onPress = function() {
if (onMouseMove != undefined) {
delete onMouseMove;
}
};

Thanks man…u saved my life!!!

u r the man!!!

it worked~

:expressionless: Now I’m almost there…

is there any thing I can do to make the MC come back?

Tks

my_btn.onPress = function() {
	if (onMouseMove != undefined) {
		delete onMouseMove;
	} else if (onMouseMove = undefined) {
		onMouseMove = function () {
			// chuck all the onMouseMove code in here
		};
	}
};

Can’t guarantee it will work, but give it a try.

:crying: it’s not workink do you is there anything I can be doing wrong?

You can always try the following. Rather than using a button, use a movieclip - I’ve called it dummyMC here. Then apply the following code to your timeline:

function mouse_move() {
	i++;
	distX = iniX - _xmouse;
	distY = iniY - _ymouse;
	distTotal = Math.sqrt(distX * distX + distY * distY);
	if (distTotal > dist) {
		iniX = _xmouse;
		iniY = _ymouse;
		np = attachMovie("p", "p" + i, i);
		np._xscale = np._yscale = Math.random() * 150 + 50;
		np.ang = Math.random() * 360;
		np.velX = .1;
		np.velY = .1;
		np._x = _xmouse;
		np._y = _ymouse;
		np.onEnterFrame = move;
	}
}
dummyMC.onMouseMove = mouse_move;
dummyMC.onPress = function() {
	if (dummyMC.onMouseMove != undefined) {
		delete dummyMC.onMouseMove;
	} else {
		dummyMC.onMouseMove = mouse_move;
	}
};

Again, no guarantee that it will work. Essentially it creates a separate function called mouse_move which it attaches to the dummyMC. When you press on the MC, it will delete the function, then reattach it next time it’s pressed.

Something is not working…I’m uploading the *.fla document can that be of any use?

Please help…I need to put my website online tonight!!!

Thanks for your attention…I’m hopping it can work now…tks again :hangover:

It works just as I stated in the earlier post. All I’ve done is change the references to dummyMC to instance name of my_btn. I’ve added a couple of comments to explain what the code is doing:

var iniX = _xmouse;
var iniY = _ymouse;
var dist = Math.random()*15+5, i = 0;
function mouse_move() {
	i++;
	distX = iniX-_xmouse;
	distY = iniY-_ymouse;
	distTotal = Math.sqrt(distX*distX+distY*distY);
	if (distTotal>dist) {
		iniX = _xmouse;
		iniY = _ymouse;
		np = attachMovie("p", "p"+i, i);
		np._xscale = np._yscale=Math.random()*150+50;
		np.ang = Math.random()*360;
		np.velX = .1;
		np.velY = .1;
		np._x = _xmouse;
		np._y = _ymouse;
		np.onEnterFrame = move;
	}
};
onMouseMove = mouse_move; // default state - start mouse_move function
my_btn.onPress = function() {
	if (onMouseMove != undefined) { // if onMouseMove is running
		delete onMouseMove; // cancel onMouseMove
		} else { // otherwise
		onMouseMove = mouse_move; // start onMouseMove
	}
};
function move() {
	this.velX += .5;
	this.velY += .5;
	this._x += Math.cos((this.ang-this.ang*.5)/(Math.PI/180))*this.velX;
	this._y += Math.sin((this.ang-this.ang*.5)/(Math.PI/180))*this.velY;
	this._alpha>0 ? this._alpha -= 2.5 : this.unloadMovie();
}

Thanks…u really helped!!!

now it worked!!!

Best Regards and take care…

:party: