Flash Cannot compare radiobutton label to a string
Why first trace prints out not second one whereas I set label in property panel to "hello"?
public function OnClick(event:MouseEvent) {
开发者_如何学Python trace(event.target.label.toString());
if (event.target.label.toString() == "hello") {
trace("hello");
};
}
it works for me... atleast with this code:
<?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>
the error must be somewhere else
Personally, I would guess that there is an extra space in the label accidentally.
Try trace(event.target.label.toString().length);
If it isn't 5, that's you're problem.
精彩评论