2013-03-09 36 views
1

我需要一个简单的淡入淡出效果,但我似乎无法弄清楚。 “淡入淡出”和“补间”完全不起作用。看起来,动画是在最新的Flex SDK中使用的效果。动画(淡入淡出)s:在纯Actionscript Flex SDK中的图像

我现在拥有的一切:

[Embed(source="assets/Back.png")] 
private static const fullScreen:Class; 
private var fullScreenButton:Image; 
fullScreenButton = new Image(); 

fullScreenButton.source = fullScreen; 
fullScreenButton.verticalAlign = "top"; 
fullScreenButton.horizontalAlign = "left"; 
fullScreenButton.visible = false; 
private var animate:Animate 
animate = new Animate(); 

// function is activated when video is loaded. 

animate.duration = 2000; 
animate.startDelay = 1000; 
fullScreenButton.visible = true; 
animate.target = fullScreenButton; 
animate.play(); 

有了这个代码是没有效果的。我究竟做错了什么? (这可能是错误的做法,所以不要假设动画是我想要特别使用的方法)。

+0

也许这不是你想听到的......但试试TweenLite。用于AS3或JS的最简单,最快速和更强大的Tweening引擎。我一直在我所有的项目中使用多年。这5行代码会这样:TweenLite.to(fullScreenButton,2,{autoAlpha:1,delay:1}); – Pier 2013-03-09 23:35:48

+0

这似乎是矫枉过正,我只需要淡化一个单一的元素。 – DominicM 2013-03-10 15:09:41

+0

也许......但是用TweenLite你可能已经解决了这个问题。我会用完整的代码发布答案,以便您可以根据需要复制粘贴。 – Pier 2013-03-10 16:34:04

回答

3

在我理解了它的尽头。在Flex中几乎没有淡化组件的例子,但是使用纯动作,所以希望这可能对某人有所帮助。

private var fade:Fade = new Fade(); 
fade.target = fullScreenButton; 
fade.duration = 1000; 
fade.alphaFrom = 1; 
fade.alphaTo = 0; 

// Call this when want to start the effect. 

fade.stop(); // this is recommended to stop previous effects. 
fade.play(); 

这将在1秒内淡出组件(在这种情况下的图像)。

1

TweenLite你可以这样做。

1)下载从GreenSock的网站http://www.greensock.com/tweenlite/

2)库文件复制在项目文件夹或在您的AS文件库中的文件。

3)导入语句

import com.greensock.TweenLite; 
import com.greensock.plugins.AutoAlphaPlugin; 

4)激活AutoAlpha插件。 autoalpha所做的是不仅仅是对alpha值进行补间,它还会在alpha为0或从alpha 0进行补间时激活/禁用可见属性。您可以只补间alpha,但在您的代码中确实使用visible = false

TweenPlugin.activate([AutoAlphaPlugin]); 

5)做舞蹈

TweenLite.to(fullScreenButton,2,{autoAlpha:1,delay:1}); 
+0

最后我想通了。你的方法很简单,但是为了一个效果而使用整个库是效率低下的。感谢您的输入。 – DominicM 2013-03-12 23:37:55

+0

我理解你的观点,也许这对于1次褪色来说是一种矫枉过正的...作为一个方面说明,如果你正在考虑在未来制作更多的补间,你应该真的看看tweenlite。它比Adobe的引擎速度更快,效率更高,并且它仅向编译的文件(swf,ipa等)添加几kb。任何现代用户界面都会使用补间,而Tweenlite是AS3甚至JS的最佳选择。 – Pier 2013-03-14 16:03:13