简体   繁体   中英

Custom event not firing in Flash Builder

I have 2 custom components in Flash Builder, A.mxml which contains B.mxml. B has a text input, and every time the text is changed I would like to call a "save()" function on A.

The relevant code in B is:

<fx:Metadata>
    [Event(name="customChange", type="flash.events.Event")]
</fx:Metadata>

...

<s:TextInput text="@{value}" valueCommit="{dispatchEvent(new Event(Event.CHANGE))}"/>

I can replace the code in valueCommit="{}" with a trace statement, and confirm that it's working as expected.

The relevant code in A is:

<widgets:B customChange="{save()}"/>

However save() is never getting called.

Why is the event not reaching A?

The metadata in your class (B.mxml) says it dispatches an event who's type/name is "customChange":

[Event(name="customChange", type="flash.events.Event")]

But the component is dispatching Event.CHANGE -- the type/name for this event is just "change".

You have two options:

  • Change your meta data to use the the same event type/name that you are dispatching:

    [Event(name="change", type="flash.events.Event")]

  • Create your own event class and dispatch that, then modify the meta data to specify that your custom event class is dispatched by B.mxml

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM