# Changing the scope of a function

**URL:** <https://forum.kirupa.com/t/changing-the-scope-of-a-function/231360>\
**Category:** Uncategorized\
**Created:** [July 4, 2007, 1:34am UTC](https://forum.kirupa.com/t/changing-the-scope-of-a-function/231360 "2007-07-04T01:34:11Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anogar](https://avatars.discourse-cdn.com/v4/letter/a/ed655f/32.png) [@Anogar](https://forum.kirupa.com/u/Anogar)\
**Post date:** [July 4, 2007, 1:34am UTC](https://forum.kirupa.com/t/changing-the-scope-of-a-function/231360/1 "2007-07-04T01:34:11Z")

</div>

Here is the script:

```auto

function delay(pFunc:Function):Void {
    this.onEnterFrame = function() {
        pFunc(param);
        delete this.onEnterFrame;
    };
}
delay(test, 1);
function test():Void {
    trace(this); //traces "[object Object]"
}

```

It’s stripped down to reproduce my issue.

I want to change the scope of the event, so that when **test** is called, it traces " **\_level0** instead of “**[object Object**”. I was thinking Delegate.create() would be the way to go, but I can’t figure out how to get that to work within the scope of this function. I know _what_ is happening, I’m just not sure how to fix it.

If I could just do it in AS3 it wouldn’t be an issue, but it’s AS2, c’est la vie.
