Cleaning things up (Code)

Okay, go easy on me here I’ll try to keep the question simple.

If, in object-attached ActionScripting I’m writing the same if statements over and over (and over) for each subsequent clickable item can I just package those if statements into a function and then just call the function on each object I attach it to?

For example - this appears on each of my draggable elements (game pieces). It’s a secondary variable watcher but applies to each game piece:

if (_root._level99.helpNeeded==3){	helpSnd = new Sound(this);
	helpSnd.attachSound("helpSound");
	helpSnd.start();
	_root._level99.numRetries = _root._level99.numRetries + 1;
}



It’d be much easier to just type the function into the object-attached ActionScript and tweak the if statement in one place.

Am I understanding one of the basic principles of working with functions?