Skip to main content
Participating Frequently
December 19, 2011
Question

Problem with manually bitmap caching a Movieclip animation more than once

  • December 19, 2011
  • 1 reply
  • 456 views

I've been working on an application that will be for both the web and mobile. All the graphic assets have been created as vectors so I can take advantage of all the different screen sizes without having to create a bunch of sets of graphics. To take advantage of the gpu, I scale the graphic to the current application scale and then draw it into a BitmapData and store it. With MovieClips I'll run through the timeline, storing all the BitmapData in a Vector. In order to keep this process from slowing down the cpu more than it needs to, I wrote a cache manager that will check to make sure that the stored instance doesn't already exist before going through the process of caching it again. So far this is all working great and I get tremendous performance out of it.

The problem comes in with people zooming on the web page. Most of the time the application's scale is set during initialization and doesn't change. When people zoom in on the web page it causes the scale to change after that first initialization and all the BitmapData that I've stored needs to be dumped and recached. Dumping it isn't the problem and recaching it isn't difficult for most things. The one problem area is a set of MovieClips that are loaded after a person logs in, which are specific to their login. Most of the time, when I'm recaching BitmapData, I'm pulling new instances out of the library the project was built with. With the loaded instances I don't have that option and I don't want to make people download all their character specific assets again. So I'm hold onto all the loaded MovieClips in a Vector and I try to cache them again, running through the animation starting from the beginning.  When I do this the BitmapData is all kinds of messed up.

After much testing, I've figured out the problem is that MovieClips need to get added to the display list for at least one frame to update their own display list when you move backwards in its timeline. When I copy out the BitmapData I'm seeing incorrect instances of children from further down the timeline. Arms and eyes will be in the wrong position, or showing multiple copies of each. Because this is going to be for the Mobile platform, I really don't enjoy the idea of putting all these MovieClips on the display list for one frame, because it will be a tremendous performance hit. Currently this is the only solution I've found. I've tried storing the original MovieClips and duplicating them before copying the animations but there doesn't seem to be a way to duplicate a MovieClip. Writing to a ByteArray fails for anything inheriting from DisplayObject and the Classname for a loaded MovieClip is just "MovieClip", so trying to create a new instance also goes nowhere. My question is, does anyone know of a way to refresh a MovieClips display list without adding it to the display list itself?

This topic has been closed for replies.

1 reply

Participating Frequently
December 19, 2011

The problem seems to actually be deeper than I initially realized. Just adding the MovieClip to the display list doesn't get rid of the problem. In order to get the MovieClip to display correctly I actually have to completely run the MovieClip through its entire timeline while it's on the stage. When it's on the stage, I can actually see it being displayed incorrectly but once it completes a full cycle it no longer displays any glitches. This seems like a bug in the Flash Player. Has anyone else run into this?