简体   繁体   中英

applying a ColorTransform stops MovieClip from playing

I have a MovieClip that consists of multiple layers, one of those layers is an animated background Shape. let's call this MyMovieClip with the background shape have the instance name "mcBackground";

I'm adding the MovieClip to the stage from ActionScript by:

var myMovieClip = new MyMovieClip();
addChild(myMovieClip);

This works fine and when the movie clip is added to the stage it plays as expected (background is moving).

The problem is when I try to apply a colorTransform to the background shape, it stops from moving. what I'm doing is this inside the MyMovieClip class:

var ct:ColorTransform = mcBackground.transform.colorTransform;
ct.color = some color value;
mcBackground.transform.colorTransform = ct;

When I do this, the background is colored correctly, but it doesn't animate anymore, it seems to be stuck at frame 1 as far as displaying although any code I have in later frames is executed. So it looks like a display issue.

what's the problem here? Is changing transform.colorTransform possible to animated shapes?

let me know if the description is not clear and I'll try to explain more.

generally, actionscript applied to any timeline-tweened object will break the tween. You can try to wrap your timeline with another clip, and apply the colorTransform to that clip.

When your actionscript code sets any display aspect of an instance (position, scale, rotation, alpha, color, filters etc), any changes due to keyframes on the timeline will not be applied to that instance anymore. The display properties of that instance will be 'frozen' (as far as the timeline is concerned) to that of the moment actionscript set the property value, and can only be changed by actionscript from then on.

This behaviour also goes for timelines/keyframes without tweens.

When actionscript does something with the instance that is not transform/filter related, this behaviour does not occur and the timeline is executed as expected. For instance, setting DisplayObject.visible does not trigger this behaviour. Also, changing text of a TextField will not trigger the behaviour.

When setting a display property on a child of the instance does not trigger the behaviour, so wrapping the instance in an extra movieclip is a good workaround.

Thanks also to doamnaT (I don't have enough rep to upvote yet). I've also found that in general dissociating timelines from the main timeline is good practice, which coincidentally avoids problems like this. Usually my main timeline is only one frame.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM