Flash无法将radiobutton标签与字符串进行比较

时间:2011-04-03 20:35:32

标签: flash actionscript-3

为什么第一个跟踪打印出的不是第二个,而我在属性面板中将标签设置为“hello”?

  public function OnClick(event:MouseEvent) {
            trace(event.target.label.toString());
    if (event.target.label.toString() == "hello") {
        trace("hello");         
    };  
  }

2 个答案:

答案 0 :(得分:1)

它适用于我...至少使用此代码:

<?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">
<fx:Script>
    <![CDATA[
        protected function radiobutton1_clickHandler(event:MouseEvent):void{
            trace(event.target.label.toString());
            if (event.target.label.toString() == "hello") {
                trace("comparison works");         
            };  
        }
    ]]>
</fx:Script>
<s:RadioButton label="hello" click="radiobutton1_clickHandler(event)"/>
</s:Application>

错误必须在其他地方

答案 1 :(得分:1)

就个人而言,我猜想标签中有一个额外的空间。

尝试trace(event.target.label.toString().length);如果不是5,那就是你的问题。