Flex 3:如何使用组件中的按钮删除组件

发布于 2024-09-25 15:17:26 字数 533 浏览 1 评论 0原文

我想使用组件内的按钮来删除它。因此,您单击它,该组件就会消失。但是,我还没有弄清楚如何从组件内部引用该组件。我应该在 click="" 中输入什么?

我的组件:popCanvas

<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml">
    <mx:Panel width="200" height="200"  title="hello"   
        click="remove=">

    </mx:Panel>
</mx:Canvas>

在主应用程序中:

var popCanvas:PopCanvas= new PopCanvas;
        popCanvas.x = 20;
        popCanvas.y = 30;
        this.addChild(popCanvas);

有什么建议吗?

谢谢。

-拉克斯米迪

I'd like to use a button within a component to remove it. So, you click it and the component is gone. But, I haven't figured out how you reference the component from within the component. What should I put in click=""?

My component: popCanvas

<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml">
    <mx:Panel width="200" height="200"  title="hello"   
        click="remove=">

    </mx:Panel>
</mx:Canvas>

In the main app:

var popCanvas:PopCanvas= new PopCanvas;
        popCanvas.x = 20;
        popCanvas.y = 30;
        this.addChild(popCanvas);

Any suggestions?

Thank you.

-Laxmidi

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

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

发布评论

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

评论(1

云巢 2024-10-02 15:17:26

好的,

这就是我的想法:

<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml">

<mx:Script>
    <![CDATA[
        public function removeMe(event:MouseEvent):void  {
            this.removeChild(event.currentTarget as DisplayObject);
        }
    ]]>
</mx:Script>

    <mx:Panel width="400" height="300"  title="hello"  click="removeMe(event)">

    </mx:Panel>
</mx:Canvas>

因此,我使用事件的 currentTarget 来引用该组件以将其删除。如果有人单击组件上的任意位置,该组件就会被删除。

谢谢。

-拉克斯米迪

Okay,

This is what I came up with:

<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml">

<mx:Script>
    <![CDATA[
        public function removeMe(event:MouseEvent):void  {
            this.removeChild(event.currentTarget as DisplayObject);
        }
    ]]>
</mx:Script>

    <mx:Panel width="400" height="300"  title="hello"  click="removeMe(event)">

    </mx:Panel>
</mx:Canvas>

So, I used the event's currentTarget to reference the component in order to remove it. If someone clicks anywhere on the component it's removed.

Thanks.

-Laxmidi

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