views:

452

answers:

2

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();}
    }
A: 

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?

Dale
the maskingLayerMC extends all the way to the end as a motion tween. while it's rewinding the mask does still exist, it's just that it looses it's gradient effect. i've solved the problem by adding the cacheAsBitmap boolean properties inside the if statement. while that works, i still don't understand why it works and perhaps it's not the best thing to do. i've posted the new code.
TheDarkInI1978
+1  A: 

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.

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;
            }

        }
    }
}
Les
doesn't seem to be a keyframe issue. to test your theory i've added a function to rewind the clip before it reaches the end. the masking layer still looses it's gradient effect.additionally, is it possible to consider easing in your code solution?
TheDarkInI1978
sorry, my easing question was dumb. please disregard.
TheDarkInI1978