Start/stop function!

I don’t know if this is the right way to do it, but I’m trying to make a function, that can be started with the press of a button, but I can’t quite get it to work, heres my code:

	function efx() {
	endY = -(_root._ymouse);
	speed = 5;
	_root.MyClip._y += (endY-_root.MyClip._y)/speed;
	}
	
	button.onPress=function(){
	efx();
}

Why is this not working?

whats not working?

If I intead of using the button.onPress=function uses the onEnterFrame = function() - It works the way it’s surposed to - BUT I want to be able to start and stop the function with the press of button!

You could take a look at the .fla!

put this into MCs’ actions tab:[AS]on(press) {
if(pressed ==0) {
pressed = 1;
} else {
pressed = 0;
}
}
onClipEvent(enterFrame) {
if (pressed ==1) {
endY = -(_root._ymouse);
speed = 5;
_y += (endY-_y)/speed;
}
}[/AS]

should work

you can do something like this…

efx = function(a, i) {
if (a) {
i.onEnterFrame = function() {
statement(s);
}
} else {
delete i.onEnterFrame;
}
}
// start
efx(1, MyClip);
// stop
efx(0, MyClip);

note. the instance name is passed to the function as a parameter, so you can use the function with any movie clip you want. :wink:

is something wrong with my AS???

kax - 4 how long you’re into Flash & AS???

Originally posted by fluid_0ne
is something wrong with my AS???

nope… i forgot to press the stupid submit reply button :stuck_out_tongue:

Originally posted by fluid_0ne
4 how long you’re into Flash & AS???

since the day i registered here.

THX guys - now its working just fine.
But I got one last question for ya, using this code:

        	endY = -(_root._ymouse);
        	speed = 5;
        	_y += (endY-_y)/speed;

Will make a MC move up and down depending on the mouse move (_ymouse). But how do I set a starting _y value for the MC? Cause no matter where I place the MC, it starts with a _y value of 0…

endY = (**yourValueHere***2)-_root._ymouse;

=)