Image

Imagegsilis wrote in Imageflashdev

Not really a problem... just curious

When you're writing class definitions, and they happen to use dispatchEvent() to broadcast events, do you always have to create a local variable to point back to the class from within the event handler?

I mean:

class thing {
    var someProperty
    function someFunction () {
       handler.onEvent = function () {
          trace(someProperty); // Will trace as undefined, it is looking for handler.someProperty
       }
    }
}

will not work. But:


class thing {
    var someProperty
    function someFunction () {
       var ClassPointer:Object = this;
        handler.onEvent = function () {
          trace(ClassPointer.someProperty);
       }
    }
}

Will work.

I understand that in the case above, someProperty does not exist inside the 'handler' object. But, is there a cleaner way to do this other than creating a function-level variable to be able to point back to the class from inside an event handler?
Has anyone ever run into this?

Thanks,
Girts