Search code examples
actionscript-3flashvector-graphics

Errors with Gradients in ActionScript


I am currently receiving the following errors:

Scene 1, Layer 'Layer 1', Frame 1, Line 172 1119: Access of possibly undefined property joints through a reference with static type flash.display:GraphicsGradientFill.


Scene 1, Layer 'Layer 1', Frame 1, Line 173 1067: Implicit coercion of a value of type flash.display:GraphicsSolidFill to an unrelated type Array.

When trying to create gradients like this:

import flash.display.JointStyle;

var stroke:GraphicsGradientFill = new GraphicsGradientFill();
stroke.joints = JointStyle.MITER;
stroke.alphas = new GraphicsSolidFill(0x102020, 1);

var fill:GraphicsGradientFill = new GraphicsGradientFill();
fill.colors = [0x0000FF, 0xEEFFEE];
fill.matrix = new Matrix();
fill.matrix.createGradientBox(70, 70, Math.PI / 2);

var path:GraphicsPath = new GraphicsPath(new Vector.<int>(), new Vector.<Number>);
path.commands.push(1, 2, 2);
path.data.push(125, 0, 50, 100, 175, 0);

var drawing:Vector.<IGraphicsData> = new Vector.<IGraphicsData>();
drawing.push(stroke, fill, path);

graphics.drawGraphicsData(drawing);

What is causing these errors?


Solution

  • Try:

    import flash.display.JointStyle;
    
    JointStyle.MITER
    

    Edit: Change stroke.joints = JoinStyle.MITER; => stroke.joints = JointStyle.MITER;

    Edit for new errors:

    GraphicsGradientFill does not have a property joints and the alphas property expects an array. I think maybe you are looking for GraphicsStroke instead of GraphicsGradientFill for the variable stroke?