我正在为Blackberry Playbook开发一个ActionScript 3.0应用程序。
我有12个装有Loader类的图像。我使用Event.ENTER_FRAME来淡入和淡出使用此事件处理程序的图像:
private function onEnterFrame(event:Event):void
{
imageToFront.alpha += 0.1; // slow fade
imageToBack.alpha -= 0.1;
if( imageToFront.alpha >= 1.0 )
{
imageToFront.alpha = 1.0;
// hide the first image
imageToBack.alpha = 0.0;
imageToBack.visible = false;
// remove the enter frame event listener
stage.removeEventListener( Event.ENTER_FRAME, onEnterFrame );
}
}
当用户点击图片时,会抛出以下点击处理程序:
private function onImageClicked(event:MouseEvent):void
{
switch((event.currentTarget as Loader).name)
{
case imageCell11Back.name:
imageToFront = imageCell11Front;
imageToBack = imageCell11Back;
break;
case imageCell11Front.name:
imageToFront = imageCell11Back;
imageToBack = imageCell11Front;
break;
case imageCell12Back.name:
imageToFront = imageCell12Front;
imageToBack = imageCell12Back;
break;
case imageCell12Front.name:
imageToFront = imageCell12Back;
imageToBack = imageCell12Front;
break;
case imageCell13Back.name:
imageToFront = imageCell13Front;
imageToBack = imageCell13Back;
break;
case imageCell13Front.name:
imageToFront = imageCell13Back;
imageToBack = imageCell13Front;
break;
case imageCell21Back.name:
imageToFront = imageCell21Front;
imageToBack = imageCell21Back;
break;
case imageCell21Front.name:
imageToFront = imageCell21Back;
imageToBack = imageCell21Front;
break;
case imageCell22Back.name:
imageToFront = imageCell22Front;
imageToBack = imageCell22Back;
break;
case imageCell22Front.name:
imageToFront = imageCell22Back;
imageToBack = imageCell22Front;
break;
case imageCell23Back.name:
imageToFront = imageCell23Front;
imageToBack = imageCell23Back;
break;
case imageCell23Front.name:
imageToFront = imageCell23Back;
imageToBack = imageCell23Front;
break;
}
stage.addEventListener(Event.ENTER_FRAME, onEnterFrame);
imageToFront.visible = true;
}
我有以下问题:
如果用户在上一张图片未达到alpha = 1.0之前点击另一张图片,则会将该图片的alpha值小于1.0。
换句话说,我必须做一些事情,将onEnterFrame
函数集alpha保留为1.0。
有什么想法吗?
我尝试使用stage.hasEventListener(Event.ENTER_FRAME)
,但它不起作用。
答案 0 :(得分:0)
尝试在imageToFront上设置事件监听器,并在imageToBack上设置如下:
imageToFront.removeEventListener(Event.ENTER_FRAME, fadeIn);
imageToFront.addEventListener(Event.ENTER_FRAME, fadeIn);
imageToBack.removeEventListener(Event.ENTER_FRAME, fadeOut);
imageToBack.addEventListener(Event.ENTER_FRAME, fadeOut);
淡化功能应如下所示:
private function fadeIn(event : Event) : void {
var currentLoader : Loader = event.target as Loader;
currentLoader.alpha += .1;
if(currentLoader.alpha >= 1) {
currentLoader.removeEventListener(Event.ENTER_FRAME, fadeIn);
}
}
private function fadeOut(event : Event) : void {
var currentLoader : Loader = event.target as Loader;
currentLoader.alpha -= .1;
if(currentLoader.alpha (inf)= 0) {
currentLoader.visible = false;
currentLoader.removeEventListener(Event.ENTER_FRAME, fadeOut);
}
}
**替换(inf)< **我不知道为什么如果我设置它会被截断...
对于补间值,您应该查看不同的补间引擎,例如TweenLite。
答案 1 :(得分:0)
我的解决方案:
private function onEnterFrame(event:Event):void
{
imageToFront.alpha += 0.1; // slow fade
imageToBack.alpha -= 0.1;
if( imageToFront.alpha >= 1.0 )
{
imageToFront.alpha = 1.0;
// hide the first image
imageToBack.alpha = 0.0;
imageToBack.visible = false;
// remove the enter frame event listener
stage.removeEventListener( Event.ENTER_FRAME, onEnterFrame );
faddingCard = false;
}
}
当用户点击图片时,会抛出以下点击处理程序:
private function onImageClicked(event:MouseEvent):void
{
if (faddingCard) return;
switch((event.currentTarget as Loader).name)
{
case imageCell11Back.name:
imageToFront = imageCell11Front;
imageToBack = imageCell11Back;
break;
case imageCell11Front.name:
imageToFront = imageCell11Back;
imageToBack = imageCell11Front;
break;
case imageCell12Back.name:
imageToFront = imageCell12Front;
imageToBack = imageCell12Back;
break;
case imageCell12Front.name:
imageToFront = imageCell12Back;
imageToBack = imageCell12Front;
break;
case imageCell13Back.name:
imageToFront = imageCell13Front;
imageToBack = imageCell13Back;
break;
case imageCell13Front.name:
imageToFront = imageCell13Back;
imageToBack = imageCell13Front;
break;
case imageCell21Back.name:
imageToFront = imageCell21Front;
imageToBack = imageCell21Back;
break;
case imageCell21Front.name:
imageToFront = imageCell21Back;
imageToBack = imageCell21Front;
break;
case imageCell22Back.name:
imageToFront = imageCell22Front;
imageToBack = imageCell22Back;
break;
case imageCell22Front.name:
imageToFront = imageCell22Back;
imageToBack = imageCell22Front;
break;
case imageCell23Back.name:
imageToFront = imageCell23Front;
imageToBack = imageCell23Back;
break;
case imageCell23Front.name:
imageToFront = imageCell23Back;
imageToBack = imageCell23Front;
break;
}
faddingCard = true;
stage.addEventListener(Event.ENTER_FRAME, onEnterFrame);
imageToFront.visible = true;
}
我添加了一个faddingCard布尔类变量来控制何时抛出onImageClick。