# Cleaning things up (Code)

**URL:** <https://forum.kirupa.com/t/cleaning-things-up-code/327723>\
**Category:** flash\
**Created:** [March 23, 2012, 3:53am UTC](https://forum.kirupa.com/t/cleaning-things-up-code/327723 "2012-03-23T03:53:33Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![macboyCanada](https://avatars.discourse-cdn.com/v4/letter/m/f19dbf/32.png) [@macboyCanada](https://forum.kirupa.com/u/macboyCanada)\
**Post date:** [March 23, 2012, 3:53am UTC](https://forum.kirupa.com/t/cleaning-things-up-code/327723/1 "2012-03-23T03:53:33Z")

</div>

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:

```auto
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?
