문제

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);
            bold_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;
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top