如何在屏幕上循环补间/自动滚动TextField

时间:2013-02-01 18:26:36

标签: actionscript-3 air tween autoscroll flash-cs6

我在Flash AS3,AIR 3.2 for iOS SDK中工作。我正在尝试使TextField显示并从屏幕右侧自动向左侧消失,然后消失,然后再次从右侧重新出现。

试着弄清楚我甚至会开始编写这个以及它背后的逻辑。目前,我有一个名为MarqueeTextField的类正在进行滚动。但它只是滚动/拼写字母字符到字符,而不是从屏幕上的点到点。当以低速滚动而不平滑时,它也会“口吃”。

public class MarqueeTextField extends TextField
{
    /** Timer that ticks every time the marquee should be updated */
    private var __marqueeTimer:Timer;

    /**
    *   Make the text field
    */
    public function MarqueeTextField()
    {
        __marqueeTimer = new Timer(0);
        __marqueeTimer.addEventListener(TimerEvent.TIMER, onMarqueeTick);
    }

    /**
    *   Callback for when the marquee timer has ticked
    *   @param ev TIMER event
    */
    private function onMarqueeTick(ev:TimerEvent): void
    {
        this.text = this.text.substr(1) + this.text.charAt(0);
    }

    /**
    *   Start marqueeing
    *   @param delay Number of milliseconds between wrapping the first
    *                character to the end or negative to stop marqueeing
    */
    public function marquee(delay:int): void
    {
        __marqueeTimer.stop();
        if (delay >= 0)
        {
            __marqueeTimer.delay = delay;
            __marqueeTimer.start();
        }
    }
}
}

我已经搜索过,似乎没有任何只使用AS3(他们使用Flash GUI)。任何人都能向我解释我是如何开始编码的,即使速度很慢也能让它变得平滑?

1 个答案:

答案 0 :(得分:1)

如果你真的必须,你可以随时使用GreenSock's Tweening engine。只需导入包,只需使用TweenLite.to()即可。此外,看起来您只是插入文本而不是实际更改文本框的位置。