|
|
|||||
Постоянно срабатывающий MOUSE_OUT
Такая задача,
есть индикатор батареи, при наведении на него появляется всплывающая подсказка, при отведении мыши с индикатора исчезает, все просто. Но нужно чтоб при наведении на подсказку она не исчезала, плюс в подсказке должны быть кнопки. Я сделал так, при отведении мыши от кнопки стартует Таймер и через секунду закрывает подсказку. При наведении на подсказку Таймер останавливается, при отведении мыши от подсказки она должна исчезнуть, вот тут-то и возникают проблемы, я вожу мышкой по подсказке и постоянно срабатывает MOUSE_OUT, mouseChildren = false помогает решить проблему, но тогда не работают кнопки в подсказке. |
|
|||||
это текст на подсказке
специально изваял пример(на haXe правда) если изменить строчку будут те-же грабли // доработать напильником и чудный компонент получится походу вопрос - как избавится от вызова MouseOut при hint.visible = false? package ; package ; import flash.display.MovieClip; import flash.display.Sprite; import flash.events.Event; import flash.events.MouseEvent; import flash.Lib; import flash.text.TextField; import flash.text.TextFieldAutoSize; import flash.Vector; import haxe.Timer; /** * ... * @author toxa */ class Main { static var hintDelay:UInt = 2000; static var textFieldActive:Bool = false; private var hintAlphaChange:Float; private var stage:MovieClip; private var button:Sprite; private var hint:Sprite; private var timer:Timer; // рисование private function crateBoxWithText(color:UInt, text:String, dst:Sprite, baloon:Bool) { var textField = new TextField(); textField.text = text; textField.autoSize = TextFieldAutoSize.CENTER; textField.mouseEnabled = textFieldActive; var width = textField.width +20; var height = textField.height + 10; dst.graphics.beginFill(color); dst.graphics.drawRoundRect( -width / 2, -height / 2, width, height, 10); dst.graphics.endFill(); if (baloon) { dst.graphics.beginFill(color); dst.graphics.moveTo(width / 2, 0); dst.graphics.lineTo(width / 2, height / 2 + 20); dst.graphics.lineTo(width / 2 - 20, 0); dst.graphics.endFill(); } dst.addChild(textField); textField.x = -textField.width / 2; textField.y = -textField.height / 2; } private function drawButton() { button = new Sprite(); stage.addChild(button); crateBoxWithText(0xeeeeee, 'Simple Button', button, false); button.y = (stage.stage.stageWidth - button.width) / 2; button.x = (stage.stage.stageWidth - button.height) / 2; } private function drawHint() { hint = new Sprite(); stage.addChild(hint); crateBoxWithText(0xffcc00, 'You clicked Simple Button - here is a hint!', hint, true); hint.y = button.y-50; hint.x = button.x - hint.width / 2; hint.visible = false; } // управление таймером private function startTimer() { if (hint.visible == true) { trace('Таймер включен'); timer = new Timer(hintDelay); timer.run = timerRun; } else { trace('Подсказка не активна, таймер включать не надо'); } } private function stopTimer() { trace('Таймер выключен'); timer.stop(); } private function timerRun () { trace('Время вышло - выключаем таймер, прячем подсказку'); hideHint(); stopTimer(); } // управление подсказкой private function animateHint(e:Event) { hint.alpha += hintAlphaChange; if ((hint.alpha > 0.99) && (hintAlphaChange>0)) { hint.alpha = 1; hint.removeEventListener(Event.ENTER_FRAME, animateHint); } if ((hint.alpha < 0.01) && (hintAlphaChange<0)) { hint.alpha = 0.1; hint.removeEventListener(Event.ENTER_FRAME, animateHint); hint.visible = false; } } private function showHint() { trace('Покажем подсказку'); hint.visible = true; hintAlphaChange = 0.1; hint.addEventListener(Event.ENTER_FRAME, animateHint); hint.addEventListener(MouseEvent.MOUSE_OVER, hintMouseOver); hint.addEventListener(MouseEvent.MOUSE_OUT, hintMouseOut); hint.addEventListener(MouseEvent.MOUSE_UP, hintMouseUp); } private function hideHint() { trace('Прячем подсказку'); hint.removeEventListener(MouseEvent.MOUSE_OVER, hintMouseOver); hint.removeEventListener(MouseEvent.MOUSE_OUT, hintMouseOver); hint.removeEventListener(MouseEvent.MOUSE_UP, hintMouseUp); hintAlphaChange = -0.1; hint.addEventListener(Event.ENTER_FRAME, animateHint); } // события кнопки private function buttonMouseOver(e:Event) { trace('button.rollOver - покажем подсказку, таймер выключен'); showHint(); stopTimer(); } private function buttonMouseOut(e:Event) { if (hint.visible == true) { trace('button.MouseOut - включаем таймер'); startTimer(); } else { trace('button.MouseOut - рудимент :), ничего не делаем'); } } // события подсказки private function hintMouseOver(e:Event) { trace('hint.MouseOver - выключаем таймер'); stopTimer(); } private function hintMouseOut(e:Event) { trace('hint.MouseOut - включаем таймер'); startTimer(); } private function hintMouseUp(e:Event) { trace('hint.MouseUp - прячем подсказку, выключаем таймер'); hideHint(); stopTimer(); } public function new() { stage = Lib.current; drawButton(); button.buttonMode = true; drawHint(); hint.buttonMode = true; timer = new Timer(hintDelay); hint.alpha = 0.1; button.addEventListener(MouseEvent.MOUSE_OVER, buttonMouseOver); button.addEventListener(MouseEvent.MOUSE_OUT, buttonMouseOut); } static function main() { new Main(); } } |
|
|||||
Используйте не MOUSE_OUT, а ROLL_OUT. Можете, заодно, почитать в чем разница
__________________
...вселенская грусть |
Часовой пояс GMT +4, время: 23:31. |
|
« Предыдущая тема | Следующая тема » |
|
|