2013-03-09 66 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