使用actionscript(如javascript)选择MXML 兄弟姐妹?

发布于 2024-09-06 07:06:09 字数 353 浏览 9 评论 0原文

我正在尝试获取 mxml 标签的同级,类似于在 javascript 中选择同级的方式。这在 Actionscript 中可能吗?

例如,当我单击 ID 为 textarea1TextArea 时,我需要它告诉我同级的 id 为 rect1,这样我就可以对其进行进一步处理。

<s:Group>
     <s:TextArea id="textarea1" click="getSibling(event)" />
     <s:Rect id="rect1" />
</s:Group>

I'm trying to get the sibling of an mxml tag similar to the way siblings are selected in javascript. Is this possible in Actionscript?

For example, when I click the TextArea with id textarea1, I need it to tell me that the sibling has an id of rect1 so I can do further processing to it.

<s:Group>
     <s:TextArea id="textarea1" click="getSibling(event)" />
     <s:Rect id="rect1" />
</s:Group>

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

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

发布评论

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

评论(3

眼前雾蒙蒙 2024-09-13 07:06:09

假设 Group、TextArea 和 Rect 是 UIComponent,我认为这应该可行:

    private function getSibling(e:Event):void {
        var parent:UIComponent = e.currentTarget.parent;

        if(parent) {
            var len:int = parent.numChildren;
            var child:UIComponent;
            for(var i:int = 0; i < len; i++) {
                child = parent.getChildAt(i) as UIComponent;
                if(child && child != e.currentTarget) {
                    trace(child.id);
                }
            }
        }
    }

Assuming Group, TextArea and Rect are UIComponents, I think this should work:

    private function getSibling(e:Event):void {
        var parent:UIComponent = e.currentTarget.parent;

        if(parent) {
            var len:int = parent.numChildren;
            var child:UIComponent;
            for(var i:int = 0; i < len; i++) {
                child = parent.getChildAt(i) as UIComponent;
                if(child && child != e.currentTarget) {
                    trace(child.id);
                }
            }
        }
    }
注定孤独终老 2024-09-13 07:06:09

我最初的想法是访问父级,然后检索其中的子级列表。

function getSibling(e:Event):void { 
   //get an array of children from the parent.
   var children:Array = e.target.parent.getChildren();  

   //process children as you wish... 
}

这是关于Javascript此处进行讨论的。

希望这有帮助。

尼克

nickgs.com

My initial thought here is to access the parent and then retrieve a list of children within it.

function getSibling(e:Event):void { 
   //get an array of children from the parent.
   var children:Array = e.target.parent.getChildren();  

   //process children as you wish... 
}

This was discussed with respect to Javascript here.

Hope this helps.

Nick

nickgs.com

你对谁都笑 2024-09-13 07:06:09

据我所知,没有办法做到这一点。但是,textarea1 和 rect1 都是该组的子级。如果您给该组一个 ID,您应该能够循环所有子项以找到 TextArea 的所有同级。

在 Flex 3 中,您可以使用 for 循环、numChildren 和 getChildAt。我怀疑 Flex 4 中也会有类似的情况。

As far as I know there is no way to do this. However, both textarea1 and rect1 are children of the Group. If you give the group an ID you should be able to loop over all the children to find all the siblings of the TextArea.

In Flex 3, you'd use a for loop, numChildren, and getChildAt. I suspect in Flex 4 it would be similar.

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