关于淡入和淡出的非常简单的AS问题

发布于 2024-08-20 14:56:13 字数 648 浏览 7 评论 0原文

很简单的问题。看看下面的代码。这是一个非常简单的带有进度条的加载程序。进度条是舞台上的一个符号,称为“条”。

我想要的只是在完成加载时淡出该栏,并淡入加载的图像。我尝试了多种方法但运气不佳。

    var loader: Loader = new Loader();
addChild(loader);

loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
function completeHandler(evt:Event):void {
};

loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressHandler);

function progressHandler(evt:ProgressEvent):void {
    var percent: int = Math.round(evt.bytesLoaded/ evt.bytesTotal * 100);
    bar.width = percent;
};

var req:URLRequest = new URLRequest("encs1.jpg");

loader.load(req);

预先感谢任何能给我指点的人!

Very simple question. Take a look at the code below. It's a very simple loader with a progress bar. The progress bar is a symbol on the stage called "bar".

All I want is to fade out the bar when it finishes loading, and fade in the image that loads. I've tried a number of approaches without much luck.

    var loader: Loader = new Loader();
addChild(loader);

loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
function completeHandler(evt:Event):void {
};

loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressHandler);

function progressHandler(evt:ProgressEvent):void {
    var percent: int = Math.round(evt.bytesLoaded/ evt.bytesTotal * 100);
    bar.width = percent;
};

var req:URLRequest = new URLRequest("encs1.jpg");

loader.load(req);

Thanks in advance to anyone who can give me any pointers!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

静赏你的温柔 2024-08-27 14:56:13

GTween

Tween

TweenLite

尝试这些库之一。 Flash 有一个内置的补间库 fl.transitions.Tween,但它并不像这些那么好。所提到的三个 API 也非常相似。

对于您的示例,您将执行此操作(使用 Tweener):

function completeHandler(evt:Event):void {
    Tweener.addTween(bar, {alpha:0, transtion:"easeOutQuad", time:.5});
    addChild(loader.content);
    loader.content.alpha = 0;
    Tweener.addTween(loader.content, {alpha:1, transition:"easeInOutQunit", time:.5, delay:.5});  
};

这将花费 0.5 秒将条形图调整到 alpha 0,将加载程序的内容(图像)调整到 alpha 1,花费 0.5 秒,在延迟 0.5 秒后,所以栏淡出,图像立即淡入。

补间动画缓动函数备忘单

GTween

Tweener

TweenLite

Try one of these libraries. Flash has a built in library for Tweening, fl.transitions.Tween, but it not nearly as nice as these. All three mentioned have a very similar API as well.

For your example, you would do this (with Tweener):

function completeHandler(evt:Event):void {
    Tweener.addTween(bar, {alpha:0, transtion:"easeOutQuad", time:.5});
    addChild(loader.content);
    loader.content.alpha = 0;
    Tweener.addTween(loader.content, {alpha:1, transition:"easeInOutQunit", time:.5, delay:.5});  
};

This will tween the bar to alpha 0 taking .5 seconds, tween the loader's content (the image) to alpha 1 taking .5 seconds, after a delay of .5 seconds, so the bar fades out and immediately the image fades in.

Cheat Sheet for Tweener easing functions

撩人痒 2024-08-27 14:56:13

我实际上并没有进行太多的 Flash 开发,但我的一位同事喜欢使用 GTween 来制作简单的动画。

http://www.gskinner.com/libraries/gtween/

如果您查看演示你会发现你可以做一些高级的事情,但做基本的淡入和淡出也应该很简单。下面是基本动画的示例,设置变量 itemToTween、secondsToAnimate 并将 alpha 更改为您希望为当前属性设置动画的属性。

new GTween(itemToTween, secondsToAnimate, { alpha: 1 }, { ease:Sine.easeOut } );

希望这对您有所帮助,直到有更多知识的人可以提供帮助。

I don't really do much flash development but a colleague of mine loves GTween for simple animation.

http://www.gskinner.com/libraries/gtween/

If you check the demos you will see you can do some advanced stuff but it is suppose to be very simple to do basic fading in and out too. Below is an example of basic animation, set the vars itemToTween, secondsToAnimate and change alpha to be the property you wish to animate the current property to.

new GTween(itemToTween, secondsToAnimate, { alpha: 1 }, { ease:Sine.easeOut } );

Hope that helps you out a little until someone with more knowledge can help.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文