1

我正在尝试使用 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();}
    }
4

2 回答 2

1

我尝试重新创建您的错误,但它对我来说很好。我的猜测是因为使用了关键帧,关键帧具有在舞台上重新实例化对象的讨厌的副作用。仅当关键帧与您的对象放置在同一层时,这才是正确的。

这只是一个猜测,因为我看不到你是如何设置你的 FLA 的。

这是适用于我的代码,主要区别在于我不使用帧脚本,而是使用包含动画影片剪辑和遮罩影片剪辑的对象的类。

package {

    import flash.display.MovieClip;
    import flash.events.Event;

    public class Test extends MovieClip {

        public var ani:MovieClip;
        public var mcMask:MovieClip;
        public var dir:int = 1;

        public function Test() {
            ani.cacheAsBitmap = true;
            mcMask.cacheAsBitmap = true;
            ani.mask = mcMask;
            addEventListener(Event.ENTER_FRAME, animate);
        }

        private function animate(e:Event) {
            ani.gotoAndStop(ani.currentFrame + dir);

            //change direction when the end or beginning is reached
            if(ani.currentFrame == ani.totalFrames || ani.currentFrame == 1) {
                dir *= -1;
            }

        }
    }
}
于 2010-02-17T22:42:08.393 回答
0

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?

于 2010-02-17T22:06:49.247 回答