我正在为 Blackberry Playbook 开发一个 ActionScript 3.0 应用程序。
我正在使用Loader 类来显示图像。
当用户单击此图像时,我想在同一位置显示另一张图像。
我怎样才能做到这一点?我想在这两个图像之间进行过渡。第二个图像将从 0 alpha 变为 100 alpha。
我正在为 Blackberry Playbook 开发一个 ActionScript 3.0 应用程序。
我正在使用Loader 类来显示图像。
当用户单击此图像时,我想在同一位置显示另一张图像。
我怎样才能做到这一点?我想在这两个图像之间进行过渡。第二个图像将从 0 alpha 变为 100 alpha。
您熟悉任何 Tween 引擎吗?如果你不是,我会推荐TweenLite 。
我通常会加载我计划使用的所有图像,然后将其中两个或更多图像堆叠在我想要的位置。任何时候都只能看到这些图像中的一个(alpha = 1)。
在您的点击处理程序上,您可以执行以下两项操作之一:
铁
这完全取决于您想要进行的过渡。对于最简单的 alpha,您可以使用 irot 建议的 Tweener 引擎,或者您可以自己做一些简单的事情。
简单:基本上,当您单击图像时,加载下一张(或已经加载)。启动一个 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