Menu:

Sponsor

Discover Master of Alchemy, our first iPad/iPhone and iPod touch game!

Follow Me

 

Forum's topics

Latest Files

Archives

Top Rated

Categories

Photo Gallery


Alessandro Crugnola on March 30, 2008 in actionscript

cacheAsBitmap hell

Last week I spent a whole day trying to solve an issue in Phoenix due to a strange problem which comes up suddenly after some code changes.
The problem was that now using the transformation tool the bounds of the selected bitmap were not detected correctly and the tool itself didn't work.
So I spent a lot of time in checking out all the recent code changes ( and they were a lot! ) to find out the possible cause...
Anyway, I was lucky to figure out the problem by accident and the problem was cacheAsBitmap!

The problem with the tool is because in order to find the correct bounds of any element on the stage it use the .concatenatedMatrix property of the element itself ( which represents the combined transformation matrixes of the display object and all of its parent objects, back to the root level ).
BUT if any of its parent display object ( not the root itself ) has the cacheAsBitmap property set to true then the concatenatedMatrix returns a wrong value!

I put a real simple flash example of what I mean. Just click on any of the 2 colored objects to activate the transform tool, then click on the "cache" button and click again on those objects to see the difference.

 

P.S. I've reported the bug in the flash player bugbase, if anyone is interested in watch or vote for it.

 

Bookmark and Share

 

 

5 comments
Thanks for the post, I fixed this issue like this: var matrix:Matrix = target.transform.concatenatedMatrix; var point = new Point(); target.localToGlobal(point); matrix.tx = point.x; matrix.ty = point.y; seems to work fine
Alessandro, I really appreciate the post. We were running into something similar not too long ago and decided to push off the issue for a while. Today it arrived at the top of my to-do list and I decided to tackle it. Luckily in our case it was fairly obvious it was a cacheAsBitmap issue, but I'm glad your post was toward the top in Google. At least we know we weren't going crazy and Elazer posted a good workaround. Again, thanks for posting. I've voted on your bug.
Hi, I actually wrote a post a year ago regarding cacheAsBitmap and problems with animation. http://k2xl.com/wordpress/2007/07/11/things-you-may-not-know-about-cacheasbitmap/
Hi! I wasted two whole weeks on this!!! i endlessly proved my matrix manipulations are right, and faced the same terrible bug. i'm SO happy i came across your post. BTW, you don't have to give up the concatenated matrix. i solved it by writing a simple getConcatenatedMatrix static method in my BitmapDataHelper: (since the matrix property of each DisplayObject is not effected by the bitmap caching)

public static function getConcatenatedMatrix(source:DisplayObject):Matrix {
var m:Matrix = new Matrix();
var scope:DisplayObject = source;
while (scope) {
m.concat(scope.transform.matrix.clone());
scope = scope.parent as DisplayObject;
}
return m;
}

Hi, I lost many time with this issue. Could you post (or send me) the source code of your published example?


Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)


Type the characters you see in the picture above.