Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AS3 vertical gradient incorrect when large

This seems to be a very straight forward thing to do and there are loads of tutorials about the subject. None of them are helping me get this right though, and I can't for the life of me figure out what's wrong.

I'm trying to create a simple Flash AS3 GUI component that has a vertical gradient. I create the sprite, and draw the gradient with beginGradientFill and a matrix with a 90 degree radian angle on it. If you look at this output, you see that its not creating a black to white vertical gradient.

package
{
   import flash.display.GradientType;
   import flash.display.Shape;
   import flash.display.Sprite;
   import flash.geom.Matrix;

   public class Main extends Sprite
   {
      public function Main()
      {
          var theWidth : Number = 800;
          var theHeight: Number = 100;

          var shape1:Shape = new Shape();
          var matrix:Matrix = new Matrix();
          matrix.createGradientBox(theWidth , theHeight, Math.PI*0.5, 0, 0);
          var colors:Array = [ 0xffffff, 0x000000];
          var alphas:Array = [ 1, 1];
          var ratios:Array = [ 0, 255];
          shape1.graphics.lineStyle(2,0xa1b0b6);
          shape1.graphics.beginGradientFill(GradientType.LINEAR,colors, alphas, ratios, matrix);
          shape1.graphics.drawRect( 0.0, 0.0, theWidth , theHeight);
          shape1.graphics.endFill();
          addChild(shape1);
      }
   }
}

If I change

matrix.createGradientBox(800, 100, Math.PI*0.5, 0, 0);

to

matrix.createGradientBox(800, 100, Math.PI, 0, 0);

it works fine - but horizontally - why is it that applying 90 degrees the fill does not work?

Thanks for your help, I really don't know whats wrong with this

like image 361
Mat Avatar asked Sep 03 '26 01:09

Mat


1 Answers

The solution would be to translate the Matrix in Y by the height of the box, it's silly working in FP9 worked fine for me without doing that, had the incubator build and looked bad, went back to 10.3 bad again.. might be that now the matrix it's rotated by the center or something that now translation is needed.

like image 113
NAZ Avatar answered Sep 05 '26 15:09

NAZ