我正在爲Blackberry Playbook開發ActionScript 3.0應用程序。兩個圖像之間的轉換
我使用Loader Class來顯示圖像。
我想在用戶單擊此圖像時在相同位置顯示另一圖像。
我該怎麼做?我想在這兩張圖片之間進行轉換。第二個圖像將從0阿爾法到100阿爾法。
我正在爲Blackberry Playbook開發ActionScript 3.0應用程序。兩個圖像之間的轉換
我使用Loader Class來顯示圖像。
我想在用戶單擊此圖像時在相同位置顯示另一圖像。
我該怎麼做?我想在這兩張圖片之間進行轉換。第二個圖像將從0阿爾法到100阿爾法。
這一切都取決於你想要做的過渡。對於最簡單的alpha,你可以通過一個Tweener引擎,像irot建議的那樣,或者你可以自己做一些簡單的事情。
簡單: 基本上,當你點擊圖像,加載下一個(或已經加載)。啓動一個enterframe監聽器來加載它。類似:
// we're assuming that "image2" is the second image and it has an alpha
// of 0.0 and visible of false. "image1" is the first image and currently
// on stage
// the on click handler for the image
private function _onImageClick(e:MouseEvent):void
{
// add a enter frame to the stage - I'm going to assume you
// have access through this.stage
this.stage.addEventListener(Event.ENTER_FRAME, this._onEnterFrame);
// make our second image visible so we can fade it up
this.image2.visible = true;
}
// called every frame
private function _onEnterFrame(e:Event):void
{
// image2 is the second image
this.image2.alpha += 0.05; // slow fade
if(this.image2.alpha >= 1.0)
{
this.image2.alpha = 1.0;
// hide the first image
this.image1.alpha = 0.0;
this.image1.visible = false;
// remove the enter frame event listener
this.stage.removeEventListener(Event.ENTER_FRAME, this._onEnterFrame);
}
}
位更復雜:查覈BitmapData類和它的merge()
或pixelDisolve()
功能:http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/BitmapData.html
您是否熟悉任何Tween引擎?如果你不是,我會推薦。
我通常會做的是加載我打算使用的所有圖像,然後將其中兩個或更多的圖像堆疊到我想要的位置。只有其中一個圖像隨時可見(alpha = 1)。
在您單擊處理程序,你可以做兩件事情之一:
IROT
另一種方法是將一個圖像對另一圖像和從圖像的一個設定的α爲0 。 – VansFannel 2011-03-16 18:25:44
你的回答很棒! – VansFannel 2011-03-17 07:18:07