Есть небольшой код:
Код AS3:
package
{
import flash.display.*;
import flash.text.*;
import flash.events.*;
public class MouseTrigger extends Sprite
{
private var text1:TextField;
private var text2:TextField;
private var format1:TextFormat;
private var format2:TextFormat;
private var clickCounter:uint = 0;
private var overCounter:uint = 0;
public function MouseTrigger()
{
textInit();
mouseInit();
}
private function textInit()
{
//--- MouseClick textfield ---//
text1 = new TextField();
text1.text = "MouseClick";
text1.x = 50;
text1.y = 50;
text1.selectable = false;
text1.autoSize = TextFieldAutoSize.LEFT;
format1 = new TextFormat();
format1.color = 0xCCCC00;
format1.font = "Verdana";
format1.size = 25;
text1.setTextFormat(format1);
addChild(text1);
//--- MouseOver textfield ---//
text2 = new TextField();
text2.text = "MouseOver";
text2.x = 50;
text2.y = 150;
text2.selectable = false;
text2.autoSize = TextFieldAutoSize.LEFT;
format2 = new TextFormat();
format2.color = 0x00CCCC;
format2.font = "Verdana";
format2.size = 25;
text2.setTextFormat(format2);
addChild(text2);
}
private function mouseInit()
{
text1.addEventListener(MouseEvent.CLICK, clickTrigger);
text2.addEventListener(MouseEvent.MOUSE_OVER, overTrigger);
}
private function clickTrigger(e:MouseEvent)
{
clickCounter ++;
text1.text = "MouseClick: triggered " + clickCounter.toString() + " times";
}
private function overTrigger(e:MouseEvent)
{
overCounter ++;
text2.text = "MouseOver: triggered " + overCounter.toString() + " times";
}
}
}
Чисто технически он работает ОК, однако есть один побочный эффект.
После нажатия на текстфилд1 (или после наведения на текстфилд2) его TextFormat почему-то сбрасывается в дефолтный.
Это нормально, или какой-то баг?
Что сделать, чтобы такого не было?
(Хотя, один вариант я вижу: в обработчике события снова запускать функцию setTextFormat(), но такое решение не очень оптимальное, походу дела.)