以编程方式倒带影片剪辑删除渐变蒙版 (FlashCS4/AS3)
我正在尝试使用 AS3 在 Flash CS4 中使用渐变蒙版创建自动倒带电影。我遇到的唯一问题是当影片剪辑到达时间线末尾时,maskingLayerMC 会丢失其渐变。因此,当电影倒带时,maskingLayer 没有渐变。当播放头到达第一帧并再次开始播放时,它会恢复梯度。
我也尝试在最后一帧上添加 .cacheAsBitmap 布尔属性,但它没有任何效果,并且 maskingLayerMC 仍然会丢失它的渐变。
--- FIRST FRAME ---
//Gradient Masking
maskedLayerMC.mask = maskingLayerMC;
maskingLayerMC.cacheAsBitmap = true;
maskedLayerMC.cacheAsBitmap = true;
//Automatically Rewind Movie Clip
var playBackwards:Boolean = false;
addEventListener(Event.ENTER_FRAME, playDirection);
function playDirection (e:Event):void
{
if (playBackwards == true)
{prevFrame();}
else
{play();}
}
--- LAST FRAME---
//Change Boolean Variable To Rewind Movie Clip (Place In Last Frame)
stop();
playBackwards = true;
[更新的工作代码]
虽然我不确定为什么这有效或者它是否是最好的解决方案。
--- FIRST FRAME ---
//Automatically Rewind Movie Clip With Gradient Masking
maskedLayerMC.mask = maskingLayerMC;
var playBackwards:Boolean = false;
addEventListener(Event.ENTER_FRAME, playDirection);
function playDirection(e:Event):void
{
if (playBackwards == true)
{
prevFrame();
maskingLayerMC.cacheAsBitmap = true;
maskedLayerMC.cacheAsBitmap = true;
}
else
{
play();
maskingLayerMC.cacheAsBitmap = true;
maskedLayerMC.cacheAsBitmap = true;
}
}
--- LAST FRAME---
//Change Boolean Variable To Rewind Movie Clip (Place In Last Frame)
stop();
playBackwards = true;
问题似乎出在 prevFrame() 函数上,因为仅在 playDirection 函数内部添加属性是不够的。所以令人沮丧的是,下面的代码不起作用。
addEventListener(Event.ENTER_FRAME, playDirection);
function playDirection(e:Event):void
{
maskingLayerMC.cacheAsBitmap = true;
maskedLayerMC.cacheAsBitmap = true;
if (playBackwards == true)
{prevFrame();}
else
{play();}
}
i'm trying to created a auto-rewind movie using a gradient mask in Flash CS4 using AS3. the only problem i'm having is when the movie clip reaches the end of the time line, the maskingLayerMC looses it's gradient. so while the movie rewinds, the maskingLayer has no gradient. it regains it's gradient when the playhead reaches the first frame and once again begins to play.
i've tried adding the .cacheAsBitmap boolean properties on the last frame as well, but it doesn't have any effect and the maskingLayerMC still looses it's gradient.
--- FIRST FRAME ---
//Gradient Masking
maskedLayerMC.mask = maskingLayerMC;
maskingLayerMC.cacheAsBitmap = true;
maskedLayerMC.cacheAsBitmap = true;
//Automatically Rewind Movie Clip
var playBackwards:Boolean = false;
addEventListener(Event.ENTER_FRAME, playDirection);
function playDirection (e:Event):void
{
if (playBackwards == true)
{prevFrame();}
else
{play();}
}
--- LAST FRAME---
//Change Boolean Variable To Rewind Movie Clip (Place In Last Frame)
stop();
playBackwards = true;
[Updated Working Code]
Although i'm not sure why this works or if it's the best solution.
--- FIRST FRAME ---
//Automatically Rewind Movie Clip With Gradient Masking
maskedLayerMC.mask = maskingLayerMC;
var playBackwards:Boolean = false;
addEventListener(Event.ENTER_FRAME, playDirection);
function playDirection(e:Event):void
{
if (playBackwards == true)
{
prevFrame();
maskingLayerMC.cacheAsBitmap = true;
maskedLayerMC.cacheAsBitmap = true;
}
else
{
play();
maskingLayerMC.cacheAsBitmap = true;
maskedLayerMC.cacheAsBitmap = true;
}
}
--- LAST FRAME---
//Change Boolean Variable To Rewind Movie Clip (Place In Last Frame)
stop();
playBackwards = true;
it seems that the problem is with the prevFrame() function since simply adding the properties once inside the playDirection function isn't enough. so the following code, frustratingly, doesn't work.
addEventListener(Event.ENTER_FRAME, playDirection);
function playDirection(e:Event):void
{
maskingLayerMC.cacheAsBitmap = true;
maskedLayerMC.cacheAsBitmap = true;
if (playBackwards == true)
{prevFrame();}
else
{play();}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我尝试重新创建你的错误,但它对我来说效果很好。我的猜测是,这是因为使用了关键帧,关键帧具有在舞台上重新实例化对象的令人讨厌的副作用。
仅当关键帧与对象放置在同一层时才会出现这种情况。
这只是一个猜测,因为我看不到你是如何设置你的 FLA 的。
这是适合我的代码,主要区别是我不使用帧脚本,而是使用包含动画影片剪辑和遮罩影片剪辑的对象的类。
I tried recreating your bug but it works fine for me. My guess is it's because of the use of keyframes, keyframes have the nasty side effect of re instantiating the objects on te stage.
This is only true if the keyframes are placed in the same layer as your object.
This is just a guess though since I can't see how you have setup your FLA.
Here is the code that works for me, with the main difference that I don't use frame scripts but a class for the object which contains the animation movieclip and the masking movieclip.
您是否尝试过在最后一帧中创建 maskingLayerMC 实例?我怀疑,由于它是在第一帧中创建的,因此当您从最后开始时,从 Flash 的角度来看,遮罩不存在。因此,直到倒回到第一帧之前,它不会被实例化。这有道理吗?
Have you tried creating a maskingLayerMC instance in the LAST frame? I'm suspecting that since it's being created in the first frame, when you're starting at the end, from Flash's standpoint the mask doesn't exist. Therefore it doesn't get instantiated until it rewinds back to the first frame. Does that make sense?