0

我在 Flash Builder 中有 2 个自定义组件,A.mxml 包含 B.mxml。B 有一个文本输入,每次更改文本时,我都想在 A 上调用“save()”函数。

B中的相关代码为:

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

...

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

我可以用跟踪语句替换代码valueCommit="{}",并确认它按预期工作。

A中的相关代码为:

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

但是save()永远不会被调用。

为什么事件没有到达 A?

4

1 回答 1

2

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

于 2012-07-27T19:14:36.500 回答