Flash toggle button

非 Y 不嫁゛ 提交于 2019-12-30 10:29:41

问题


I need a button in Flash/AS3 that toggles between on and off. So I was glad to see that the Button class has the toggle property that lets me have that behavior. I was less happy to see that what I get when I make something a "button" in the Flash file is an instance of SimpleButton class, which does not have that option.

Is there a way to either get a Button instance from the .fla, or get the SimpleButton to behave as a toggle?


回答1:


Here's how I coded my way around this:

private buttonState:Boolean;

private function buttonToggle(button:SimpleButton){
    var currDown:DisplayObject = button.downState;
    button.downState = button.upState;
    button.upState = currDown;
    buttonState = !buttonState;
}

private function clickEvent(e:MouseEvent){
    buttonToggle(e.target);
}

I didn't put the code in the clickEvent function, because this allows me to toggle the button from elsewhere in the code.




回答2:


You can drag a Button from the Components window. Is that what you are looking for?




回答3:


I think this might help you alot: http://actionscriptexamples.com/2008/11/26/creating-toggle-buttons-in-flash-with-actionscript-30/

It is actionscript only. But it's the same if you drag the Button component to the stage and asign an instance name to it. That way to can access it from the as script.



来源:https://stackoverflow.com/questions/560490/flash-toggle-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!