Array<Int> should be Array<UInt>

Can’t seem to work this one out.

I’m using the flash API to draw out a gradient fill. It works fine on neko but gives a type error in flash.

source/Graphics.hx:30: characters 57-65 : Array should be Array
source/Graphics.hx:30: characters 57-65 : Type parameters are invariant
source/Graphics.hx:30: characters 57-65 : Int should be UInt
source/Graphics.hx:30: characters 57-65 : For function argument ‘colors’

var sprite = new FlxSprite().makeGraphic(width,height,0);

var _colours = [0x13A5CA, 0x0D6C82];
var _alphas = [1, 1];
var _ratios = [0, 255];
var _matrix = new Matrix();

var _holeRadius = width;
var _holeX = width/2;
var _holeY = height/2;

_matrix.createGradientBox(_holeRadius, _holeRadius/2, 0, _holeX - _holeRadius/2, _holeY - _holeRadius/4);

var _shape = new openfl.display.Shape();

_shape.graphics.clear();
_shape.graphics.beginGradientFill(GradientType.RADIAL, _colours, _alphas, _ratios, _matrix);
_shape.graphics.drawRect(0,0,width,height);
_shape.graphics.endFill();

sprite.pixels.draw(_shape);

I understand that flash uses unsigned integers … But in this case I’m just defining _colors as a standard array - Do I need to do an #if flash for this ? Is there no other (cleaner) way to do it ?

Looking at openfl/display/Graphics.hx beginGradientFill it defines colors as Array<Dynamic> - why is the compiler complaining ?

Thanks for reading.

I replaced the _colours line with

var _colours #if flash : Array<UInt> #end = [0x13A5CA, 0x0D6C82];

It compiles but I’m getting just black (in flash, works in neko). I traced out _colours and the values are fine.

You think it’s the final draw line

sprite.pixels.draw(_shape);

? I saw that in the haxeflixel tutorial they switched draw out for copyPixels for the flash platform but I don’t really understand the reason for the difference (and I’ve tried it here - no dice). http://haxeflixel.com/documentation/part-xiii-polish-finishing-up-and-juice/

Bizarrely if I change the line to

sprite.framePixels.draw(_shape);

it works in flash but crashes in neko …

Anyone know why ?

For anyone interested - I’ve just noticed that what I’m trying to do (use the standard Flash API to do gradient fills) is done quite cleanly in HaxeFlixel’s flixel.util.FlxGradient.hx https://github.com/HaxeFlixel/flixel/blob/dev/flixel/util/FlxGradient.hx

I still don’t really understand how they do it without #if flash. They seem to cover my first issue (Int should be UInt) using cast(colours) when passing them in. As for drawing … I have to go through it carefully. All the drawing, blitting, copying stuff at the moment is beyond me … They don’t do what I did above, though (using framePixels instead of pixels. In fact, they don’t seem to use pixels at all…).

Hope that helps …

I know that I am reviving a very old thread here, but I am running into what seems to be the exact same issue. The difference is, I am not trying to use OpenFL directly, but simply trying to go through the tutorial for HaxeFlixel (which has been linked by @mike1101 above: http://haxeflixel.com/documentation/tutorial/).

As a matter of fact, I am just coming back to working through the tutorial after a hiatus of about a month, so the issue at this point may be mismatched libraries. I seem to be using Haxe 4.0.0-preview4, Lime 6.4.0, OpenFL 8.3.0, and Flixel 4.4.2. I do not remember hitting any compiler issues when starting the tutorial (in May of 2018). I had stopped halfway through this step, and now, upon completing the code in that step, I receive the aforementioned errors.

The full text of my terminal follows:

Executing task: C:\Program Files\HaxeToolkit\haxe\haxelib.exe run lime build flash -debug -Dfdb <

C:/Program Files/HaxeToolkit/haxe/lib/openfl/8,3,0/src/format/swf/instance/Shape.hx:45: characters 45-51 : Array<Int> should be Array<UInt>
C:/Program Files/HaxeToolkit/haxe/lib/openfl/8,3,0/src/format/swf/instance/Shape.hx:45: characters 45-51 : Type parameters are invariant
C:/Program Files/HaxeToolkit/haxe/lib/openfl/8,3,0/src/format/swf/instance/Shape.hx:45: characters 45-51 : Int should be UInt
C:/Program Files/HaxeToolkit/haxe/lib/openfl/8,3,0/src/format/swf/instance/Shape.hx:45: characters 45-51 : For function argument 'colors'
C:/Program Files/HaxeToolkit/haxe/lib/openfl/8,3,0/src/format/swf/instance/MorphShape.hx:67: characters 44-50 : Array<Int> should be Array<UInt>
C:/Program Files/HaxeToolkit/haxe/lib/openfl/8,3,0/src/format/swf/instance/MorphShape.hx:67: characters 44-50 : Type parameters are invariant
C:/Program Files/HaxeToolkit/haxe/lib/openfl/8,3,0/src/format/swf/instance/MorphShape.hx:67: characters 44-50 : Int should be UInt
C:/Program Files/HaxeToolkit/haxe/lib/openfl/8,3,0/src/format/swf/instance/MorphShape.hx:67: characters 44-50 : For function argument 'colors'
C:/Program Files/HaxeToolkit/haxe/lib/openfl/8,3,0/src/format/swf/exporters/ShapeCommandExporter.hx:62: characters 43-49 : Array<UInt> should be Array<Int>
C:/Program Files/HaxeToolkit/haxe/lib/openfl/8,3,0/src/format/swf/exporters/ShapeCommandExporter.hx:62: characters 43-49 : Type parameters are invariant
C:/Program Files/HaxeToolkit/haxe/lib/openfl/8,3,0/src/format/swf/exporters/ShapeCommandExporter.hx:62: characters 43-49 : UInt should be Int
C:/Program Files/HaxeToolkit/haxe/lib/openfl/8,3,0/src/format/swf/exporters/ShapeCommandExporter.hx:62: characters 43-49 : For function argument 'colors'
The terminal process terminated with exit code: 1

Does anyone have an idea regarding a potential fix for this issue?

This looks like a bad import. Do you import format.swf anywhere in your code?