سؤال

I'm encountering something a bit bizarre, but maybe someone else came across this before.

I've got a base class, that doesn't extend anything. Let's call it...

public class FooBar {
    //...
}

But I want to bind EVERY single one of its exposed properties:

[Bindable] public class FooBar {
    public var propertyOne:String;
    public var propertyTwo:String;
}

While Debugging / Profiling the class, I'm noticing that each time a property is changed - the instance of FooBar is calling ".dispatchEvent()" on it. But my class doesn't extend EventDispatcher.

What gives?

Does this mean, at compile time, my class automatically extends EventDispatcher or some other class with the ability to dispatch events? How could I listen to the PropertyChangeEvent if my class doesn't have the "addEventListener" method declared in it?

هل كانت مفيدة؟

المحلول

When you use the [Bindable] metadata the Flex compiler generates a lot of code for you. If you want to know what happens exactly take a look at the answers to What does the Flex [Bindable] tag do? and the links that are posted there.

To answer your question: No, your class doesn't extend EventDispatcher. However, the compiler changes your class so that it will implement the IEventDispatcher interface. The generated implemenation of that interface uses an instance of EventDispatcher.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top