![]() |
|
||||||||||
|
|||||
|
Banned
Регистрация: Mar 2013
Сообщений: 1,864
|
У меня не работают компоненты адоби, но вот приблизительно так можно сделать -
package { import flash.display.Sprite; import flash.events.MouseEvent; import flash.text.TextField; import flash.text.TextFormat; public class Main extends Sprite { private static const PINC:uint = 0xFF6986; private static const WHITE:uint = 0xF8FAFF; private static const LILAC:uint = 0xBB63CC; private const BUTTON_WIDTH:int = 70; private const BUTTON_HEIGHT:int = 45; private var _currentButton:Sprite; private var _container:Sprite; public function Main() { _container = new Sprite(); super.addChild(_container); var button:Sprite; var label:TextField; var offsetX:int; for (var i:int = 0; i < 8; i++) { button = createButton(BUTTON_WIDTH, BUTTON_HEIGHT, LILAC); button.x = offsetX; offsetX += BUTTON_WIDTH + 5; label = createLabel(i.toString()); button.addChild(label); _container.addChild(button) } _container.addEventListener(MouseEvent.MOUSE_UP, container_mouseUpHandler); } private function container_mouseUpHandler(event:MouseEvent):void { var button:Sprite = event.target as Sprite; var label:TextField; if (button != _currentButton) { if (_currentButton != null) { label = _currentButton.getChildAt(0) as TextField; label.setTextFormat(defauilTextFormat()); } _currentButton = button; label = _currentButton.getChildAt(0) as TextField; label.setTextFormat(pincTextFormat()); } } private function createLabel(text:String):TextField { var label:TextField = new TextField(); label.defaultTextFormat = defauilTextFormat(); label.mouseEnabled = false; label.text = text; return label; } private function defauilTextFormat():TextFormat { var textFormat:TextFormat = new TextFormat(); textFormat.size = 40; textFormat.bold = true; textFormat.color = WHITE; return textFormat; } private function pincTextFormat():TextFormat { var textFormat:TextFormat = new TextFormat(); textFormat.size = 40; textFormat.bold = true; textFormat.color = PINC; return textFormat; } private function createButton(w:Number, h:Number, color:uint):Sprite { var button:Sprite = new Sprite(); button.graphics.beginFill(color); button.graphics.drawRect(0, 0, w, h); button.graphics.endFill(); return button; } } } Вы наверняка будете использовать встроенные компоненты, по этому нужно обратить внимание лишь на строки ниже. Смысл в том, чтобы все кнопки сложить в один контейнер и подписать его на клик. В обработчике клика вытаскивать кнопку, у неё лейбел и уже его свойству текст задавать цвет. И так же сделать поле текущая кнопка, чтобы отменять у предыдущей розовый цвет. private var _currentButton:Sprite; private var _container:Sprite; private function container_mouseUpHandler(event:MouseEvent):void { var button:Sprite = event.target as Sprite; var label:TextField; if (button != _currentButton) { if (_currentButton != null) { label = _currentButton.getChildAt(0) as TextField; label.setTextFormat(defauilTextFormat()); } _currentButton = button; label = _currentButton.getChildAt(0) as TextField; label.setTextFormat(pincTextFormat()); } } Цитата:
Последний раз редактировалось Akopalipsis; 26.04.2014 в 00:46. |
![]() |
Часовой пояс GMT +4, время: 20:44. |
|
|
« Предыдущая тема | Следующая тема » |
|
|