2011-03-16 58 views
0

我正在为Blackberry Playbook开发ActionScript 3.0应用程序。两个图像之间的转换

我使用Loader Class来显示图像。

我想在用户单击此图像时在相同位置显示另一图像。

我该怎么做?我想在这两张图片之间进行转换。第二个图像将从0阿尔法到100阿尔法。

回答

1

这一切都取决于你想要做的过渡。对于最简单的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

+0

你的回答很棒! – VansFannel 2011-03-17 07:18:07

1

您是否熟悉任何Tween引擎?如果你不是,我会推荐​​。

我通常会做的是加载我打算使用的所有图像,然后将其中两个或更多的图像堆叠到我想要的位置。只有其中一个图像随时可见(alpha = 1)。

在您单击处理程序,你可以做两件事情之一:

  • 吐温可见图像的Alpha下降到0,然后有一个的onComplete处理吐温你的下一个图像的alpha高达1
  • 另外,你可以只有两个补间一次运行。一会补间可见图像的Alpha下降到0,对方补间的下一个图像的alpha高达1个

IROT

+0

另一种方法是将一个图像对另一图像和从图像的一个设定的α为0 。 – VansFannel 2011-03-16 18:25:44