Flex 构建器层次结构输出中的 Action script3 跟踪

发布于 2024-11-09 00:40:59 字数 1490 浏览 0 评论 0原文

我正在使用 Flex builder 4.5,我的问题是这个代码不起作用,当我使用 Trace(event.target) 时,我在控制台中得到以下结果,

deleteme.ApplicationSkin2._ApplicationSkin_Group1.contentGroup.VGroup5.button1

如果我替换“if”语句中的这一长行,代码就可以工作。 (deleteme是项目名称)。你不认为它应该只说button1而不是所有层次结构的长线,如果是这样的话我们如何缩短它?

<?xml version="1.0" encoding="utf-8"?>
 <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
           xmlns:s="library://ns.adobe.com/flex/spark" 
           xmlns:mx="library://ns.adobe.com/flex/mx" 
           minWidth="955" minHeight="600"
           initialize="handleClick(event)">
<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>

<fx:Script>
    <![CDATA[
        private function init():void{
            button2.addEventListener(MouseEvent.CLICK, handleClick);
        }
        private function handleClick(event:Event):void{
            trace(event.target);
            if(event.target == "button1"){
                button1.label = "Button 1 clicked";
            }else if(event.target == "button2"){
                button2.label = "Button 2 clicked";
            }
        }

    ]]>
</fx:Script>
<s:VGroup width="100%">
    <s:Button id="button1" label="Button 1" click="handleClick(event)"/>
    <s:Button id="button2" label="Button 2" />
</s:VGroup>
</s:Application>

预先感谢,

(我尝试使用 sdk 4.1 还是相同的答案)

i am using Flex builder 4.5 and my problem is this that this code doos not work, when i used trace(event.target) i get following in result in console,

deleteme.ApplicationSkin2._ApplicationSkin_Group1.contentGroup.VGroup5.button1

And if i replace this long line in 'if' statement code works.(deleteme is the project name). Dont you think it should only say button1 instead of this all long line with all hierarchy , if that is the case then how we can shortend it?

<?xml version="1.0" encoding="utf-8"?>
 <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
           xmlns:s="library://ns.adobe.com/flex/spark" 
           xmlns:mx="library://ns.adobe.com/flex/mx" 
           minWidth="955" minHeight="600"
           initialize="handleClick(event)">
<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>

<fx:Script>
    <![CDATA[
        private function init():void{
            button2.addEventListener(MouseEvent.CLICK, handleClick);
        }
        private function handleClick(event:Event):void{
            trace(event.target);
            if(event.target == "button1"){
                button1.label = "Button 1 clicked";
            }else if(event.target == "button2"){
                button2.label = "Button 2 clicked";
            }
        }

    ]]>
</fx:Script>
<s:VGroup width="100%">
    <s:Button id="button1" label="Button 1" click="handleClick(event)"/>
    <s:Button id="button2" label="Button 2" />
</s:VGroup>
</s:Application>

thanks in advance,

(i tried with sdk 4.1 still same answer)

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

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

发布评论

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

评论(1

撑一把青伞 2024-11-16 00:40:59

请改用以下代码:

<?xml version="1.0" encoding="utf-8"?>
 <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
           xmlns:s="library://ns.adobe.com/flex/spark" 
           xmlns:mx="library://ns.adobe.com/flex/mx" 
           minWidth="955" minHeight="600"
           initialize="handleClick(event)">
<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>

<fx:Script>
    <![CDATA[
        private function init():void{
            button2.addEventListener(MouseEvent.CLICK, handleClick);
        }
        private function handleClick(event:Event):void{
            trace(event.target);
            if(event.currentTarget == button1){
                button1.label = "Button 1 clicked";
            }else if(event.currentTarget == button2){
                button2.label = "Button 2 clicked";
            }
        }

    ]]>
</fx:Script>
<s:VGroup width="100%">
    <s:Button id="button1" label="Button 1" click="handleClick(event)"/>
    <s:Button id="button2" label="Button 2" />
</s:VGroup>
</s:Application>

将视觉对象与字符串进行比较是没有意义的。将物体与物体本身进行比较。

Use the following code instead:

<?xml version="1.0" encoding="utf-8"?>
 <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
           xmlns:s="library://ns.adobe.com/flex/spark" 
           xmlns:mx="library://ns.adobe.com/flex/mx" 
           minWidth="955" minHeight="600"
           initialize="handleClick(event)">
<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>

<fx:Script>
    <![CDATA[
        private function init():void{
            button2.addEventListener(MouseEvent.CLICK, handleClick);
        }
        private function handleClick(event:Event):void{
            trace(event.target);
            if(event.currentTarget == button1){
                button1.label = "Button 1 clicked";
            }else if(event.currentTarget == button2){
                button2.label = "Button 2 clicked";
            }
        }

    ]]>
</fx:Script>
<s:VGroup width="100%">
    <s:Button id="button1" label="Button 1" click="handleClick(event)"/>
    <s:Button id="button2" label="Button 2" />
</s:VGroup>
</s:Application>

It has no sense to compare visual objects with strings. Compare objects with objects themselves.

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