简体   繁体   English

自定义事件未在Flash Builder中触发

[英]Custom event not firing in Flash Builder

I have 2 custom components in Flash Builder, A.mxml which contains B.mxml. 我在Flash Builder中有2个自定义组件,A.mxml包含B.mxml。 B has a text input, and every time the text is changed I would like to call a "save()" function on A. B有一个文本输入,每次文本更改时我想在A上调用“save()”函数。

The relevant code in B is: B中的相关代码是:

<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. 我可以用trace语句替换valueCommit="{}"的代码,并确认它按预期工作。

The relevant code in A is: A中的相关代码是:

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

However save() is never getting called. 但是,永远不会调用save()

Why is the event not reaching A? 为什么活动没有达到A?

The metadata in your class (B.mxml) says it dispatches an event who's type/name is "customChange": 类中的元数据(B.mxml)表示它调度了一个类型/名称为“customChange”的事件:

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

But the component is dispatching Event.CHANGE -- the type/name for this event is just "change". 但该组件正在调度Event.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")] [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 创建自己的事件类并调度该事件类,然后修改元数据以指定由B.mxml调度自定义事件类

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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