AS3 - 使文本在悬停时增长

时间:2016-09-05 09:58:24

标签: actionscript-3

我希望文本悬停在文本上时,我理解如何添加事件监听器并检测它何时被悬停,只是不了解如何实际执行增长部分。 我也不希望它立刻从一种尺寸跳到另一种尺寸,我希望它实际上显示它在增长,基本上它会快速增长,如果你将鼠标悬停在正常尺寸上,可以说是2倍,这些是按钮主屏幕,所以当你将鼠标悬停在按钮上时,我希望这些按钮能够引人注目。

public function _H_o(_arg1:String, _arg2:int, _arg3:Boolean) {
    name = _arg1;
    this.text_ = new SimpleText(_arg2, 0xD85A00, false, 0, 0, "Myriad Pro");
    this.text_.setBold(true);
    this.text_.text = _arg1.toLowerCase();
    this.text_.updateMetrics();
    this.text_.filters = [new DropShadowFilter(0, 0, 0, 0.5, 12, 12)];
    addChild(this.text_);
    this._U_r = _arg3;
    this._0H_X_ = width;
    this._N_a = height;
    this.activate();
}
public function activate():void{
    addEventListener(MouseEvent.MOUSE_OVER, this.onMouseOver2);
    this.active = true;
} 
protected function onMouseOver2(_arg1:MouseEvent):void {
    //the code that makes the text medium-paced grow to 2x it size
}

1 个答案:

答案 0 :(得分:0)

以下是使用greensock作为结对库的一个非常基本的示例:

    public class Main extends Sprite 
    {
    private var _textField:TextField;
    private var _textFormat:TextFormat;

    public function Main() 
    {
        _textField = new TextField();
        _textFormat = new TextFormat();
        _textFormat.size = 50;

        _textField.defaultTextFormat = _textFormat;
        _textField.text = "text";

        addChild(_textField);

        //repeat -1 so the animation continue forever
        //yoyo to go both ways from the begining to the end and  from the end to the begining
        TweenMax.to(_textFormat, 1, {size:10, yoyo:true, repeat: -1, onUpdate:updateTextSize});
    }

    private function updateTextSize():void 
    {
        //text needs to be preset again
        _textField.text = "text";
        _textField.defaultTextFormat = _textFormat;
        trace(_textFormat.size);
    }
}

我希望它可以帮到你。