How do I fix this potential bug with the Button Component in Flash?
I need to use the Button component from the UI Components Panel in the Flash IDE, with the toggle property set to true.
If I use it with a timeline script it works great.
If I use within a class(a Document Class), the selected property is reversed (I get true when it's not toggled and vice versa).
Also if I set toggle to false in the Property Inspector, then set toggle to true in the document class, it still traces out as false. If I invalidate, I toggle traces true, but the selected property always traces false.
Timeline code is as simple as this:
bold_b.addEventListener(MouseEvent.CLICK, onClick);
function onClick(event:MouseEvent):void {
trace(event.currentTarget.selected);
}
Document class is simple as well:
package
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
public class ButtonTester extends MovieClip
{
public function ButtonTester()
{
//in timeline works fine, in class it's the other way around
bold_b.addEventListener(MouseEvent.CLICK, onClick);
bold_b.toggle = true;
bold_b.invalidate('toggle',true);
bol开发者_开发百科d_b.drawNow();
stage.invalidate();
trace('bold_b.toggle: ' + bold_b.toggle);
function onClick(event:MouseEvent):void {
trace(event.currentTarget.selected);
}
}
}
}
Currently I'm using Flash CS3. I've got Flash Player 10 installed. Don't know the components 'build' version, but they were written in 2007 under Flash Player 9.0.28.0
Does anyone know how to get around this ?
and what about this?
import fl.controls.Button;
var myButton:Button = new Button();
myButton.toggle = true;
myButton.selected = true;
myButton.label = "selected:" + myButton.selected;
myButton.width = 120;
myButton.move(10, 10);
myButton.addEventListener(Event.CHANGE, changeHandler);
addChild(myButton);
function changeHandler(event:Event):void {
var myBtn:Button = event.currentTarget as Button;
myBtn.label = "selected:" + myBtn.selected;
}
精彩评论