May 17, 2009
A fix for createGradientBox()

Whilst playing around with some geometry that involved gradient fills I had to realize that the native implementation of Flash's createGradientBox() is unfortunately entirely useless as soon as you try to introduce rotation and scaling to a gradient. The reason seems to be that internally the order of matrix operations is unsuited for that task.

Maybe I've searched not thoroughly enough, but I didn't find any solution for this out there. So I've written a tiny class that fixes it. Here's a comparison of the difference between matrix.createGradientBox() and my new GradientMatrix.getGradientBox()

To use it you can use the same values that you would use in the native function, the only difference is that you don't have to create a new Matrix first. The syntax is var myGradientMatrix:Matrix = GradientMatrix.getGradientBox( width, height, rotation, tx, ty);

Download GradientMatrix.as here

Posted at May 17, 2009 12:58 AM | Further reading
Comments

great ! thanks for the class ! ! !

Posted by: dim on May 17, 2009 10:33 AM

Interesting approach, although I haven't experienced the underlying problem you described.
If you have the matrix for your geometry transforms you shoud be able to just concat it to the gradient's original matrix from the initial createGradientBox. That has always worked fine for me.

Posted by: Greg Dove on May 19, 2009 01:02 AM

This fix is definitely not rocket science. It only "repairs" what I think is wrong with the way the default method works. Also in the case of filling shapes that I draw with the drawing API there are no geometry transforms in the first place.

Posted by: Mario Klingemann on May 19, 2009 01:38 PM

say, is this your post
http://www.dearadobe.com/index.php?gripeID=8926

Posted by: makc on August 10, 2009 11:02 PM

Rocket science or not...I thoroughly appreciate this. I have avoided using createGradientBox all this time for the fact it's behavior is confusing to me. I'm already confused enough after doing Matrix transformations.

I think I will start playing around with pretty gradients again.

Posted by: Keith H on September 6, 2009 06:09 PM

Tolle Sache, danke!

Posted by: andreas on March 29, 2011 05:45 PM
Post a comment
Name:


Email Address:


URL:


Comments:


Remember info?



Thank you!

Most Visited Entries
Sketches, Works & Source Code
Lectures
Contact
Backlog
In Love with
Powered by
Movable Type 2.661

© Copyright Mario Klingemann

Syndicate this site:
RSS 1.0 - RSS 2.0

Quasimondo @ flickr
Quasimondo @ LinkedIn
Quasimondo @ Twitter
Quasimondo @ Facebook
Quasimondo @ MySpace
Quasimondo is a Bright
Citizen of the TRansnational Republic
My other blog in german
Impressum


My family name is written Klingemann,
not Klingelmann, Klingeman, Klingaman, Kingemann,
Kindermann, Killingaman, Klingman, Klingmann, Klingonman
Klingemman, Cleangerman, Klingerman or Kleangerman

profile for Quasimondo at Stack Overflow, Q&A for professional and enthusiast programmers