# Mc functions inside functions

**URL:** <https://forum.kirupa.com/t/mc-functions-inside-functions/31720>\
**Category:** Uncategorized\
**Created:** [September 26, 2003, 4:07am UTC](https://forum.kirupa.com/t/mc-functions-inside-functions/31720 "2003-09-26T04:07:41Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jtax](https://avatars.discourse-cdn.com/v4/letter/j/9f8e36/32.png) [@jtax](https://forum.kirupa.com/u/jtax)\
**Post date:** [September 26, 2003, 4:07am UTC](https://forum.kirupa.com/t/mc-functions-inside-functions/31720/1 "2003-09-26T04:07:41Z")

</div>

I created an empty movie clip. The object in the clip is drawn with actionscript.

I wanted for the object to do different things when different keys were pressed. Like so:

```auto
clip.onKeyDown = function() {
if (Key.getCode() == Key.DOWN) {
clip.onEnterFrame = function() {
_root.callFunction();
}
} else if (Key.getCode() == Key.UP) {
clip.onEnterFrame = function() {
_root.callFunction();
}
}
}

```

It’s a simple example showing that the onEnterFrame function does about the same thing for each keys. Am i doing this right, or can the onEnterFrame function be defined once and i can call it from the onKeyDown function?

Thanks,  
Jerome
