Flex 4 冒泡自定义事件

发布于 2024-08-13 02:41:27 字数 590 浏览 2 评论 0原文

如何在 Flex 4 中创建冒泡自定义事件?

要在 MXML 中创建和公开自定义事件,您需要在将使用以下行调度事件的组件中声明它:

<fx:Metadata>
        [Event(name="select", type="my.engine.events.SelectionEvent")]
</fx:Metadata>

这允许您:

<my:CustomComponent select="doSomething()"/>

但是,如何使该气泡向上。我想做这个

<s:DataGroup select="doSomethingForAll();">
   <s:itemRenderer>
      <fx:Component>
         <my:CustomComponent/>
      </fx:Component>
   </s:itemRenderer>
</s:DataGroup/>

谢谢!

How to create a bubbling custom event in Flex 4?

To create and expose a custom event in MXML, you need to declare it at the component that will dispatch the event with this line:

<fx:Metadata>
        [Event(name="select", type="my.engine.events.SelectionEvent")]
</fx:Metadata>

This allows you to:

<my:CustomComponent select="doSomething()"/>

However, how do you make this bubble upwards. I want to do this

<s:DataGroup select="doSomethingForAll();">
   <s:itemRenderer>
      <fx:Component>
         <my:CustomComponent/>
      </fx:Component>
   </s:itemRenderer>
</s:DataGroup/>

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

〗斷ホ乔殘χμё〖 2024-08-20 02:41:27

您的自定义事件必须扩展事件。在构造函数中,您会发现 name:stringbubbling:booleancacellable:boolean 作为参数。

将冒泡参数设置为 true。在您的示例中,元数据标记必须位于您的数据组标记中。

Your Custom event must extend Event. On constructor you'll find name:string, bubbling:boolean, and cacellable:boolean as arguments.

Set the bubbling parameter to true. In your example, the metadata tag must be in your DataGroup tag.

迷离° 2024-08-20 02:41:27

一种可能的解决方案(但不完全是我想要的)是在数据组级别添加这行代码。

this.addEventListener(SelectionEvent.SELECTED, onSelect);

这将确保 CustomComponent 触发的所有事件都不会发生。

One possible solution but not exactly what i was looking for is to add this line of code at the DataGroup level.

this.addEventListener(SelectionEvent.SELECTED, onSelect);

This will ensure all events fired by CustomComponent is cought.

简单气质女生网名 2024-08-20 02:41:27

您可以使用内置于扩展类中的指定自定义元标记数据信息来扩展 s:DataGroup 容器,也可以从 itemRenderer 的“select”事件处理程序中调用“doSomethingForAll()”方法,请参阅下面的代码:

<s:DataGroup         
    dataProvider="{instructions}"        
    width="100%">        
    <s:itemRenderer>
        <fx:Component>
            <my:CustomComponent                    
                select="rendererSelect()">
                <fx:Script>
                    <![CDATA[

                        protected function rendererSelect():void
                        {
                            outerDocument.doSomethingForAll();
                        }

                    ]]>
                </fx:Script>
            </my:CustomComponent>
        </fx:Component>
    </s:itemRenderer>                
</s:DataGroup> 

You can either extend s:DataGroup container with specified custom metatag data information built-in into the extended class or you can either call "doSomethingForAll()" method from itemRenderer's "select" event handler, see code below:

<s:DataGroup         
    dataProvider="{instructions}"        
    width="100%">        
    <s:itemRenderer>
        <fx:Component>
            <my:CustomComponent                    
                select="rendererSelect()">
                <fx:Script>
                    <![CDATA[

                        protected function rendererSelect():void
                        {
                            outerDocument.doSomethingForAll();
                        }

                    ]]>
                </fx:Script>
            </my:CustomComponent>
        </fx:Component>
    </s:itemRenderer>                
</s:DataGroup> 
失去的东西太少 2024-08-20 02:41:27

捕获 dataGroups select 事件,然后调度 doSomethingForAll()

确保 doSomethingForAll 事件的冒泡属性设置为 true。

然后,在显示列表中侦听其上方的 doSomethingForAll 的任何事件侦听器都将被调用。

Catch the dataGroups select event and then dispatch a doSomethingForAll()

Make sure the doSomethingForAll event has it's bubbling property set to true.

Then any event listeners listening for doSomethingForAll above it in the display list will get called.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文