Scale9grid issue on html5

Hi there ^^
I’ve some dialog boxes whose background scales pretty bad, so in flash i used a 9scale grid to only stretch the center part of the box, here’s how it’s in flash:

The red part is the rectangle for the 9scalegrid property (it’s not exported in the game) so you can see if i’m doing something wrong.
That’s the code for the red rectangle.

_background.scale9Grid = new Rectangle(32, 28, 141, 3);

But that’s the result i’m getting once the background of the box is stretched: (the corners are streched but they shouldn’t )

Is it not supported for the html5 export ? or am i doing something wrong ? At first i thought the gradient was the cause, so i changed to an unified color but the issue is still there :frowning:.

Thanks for reading :slight_smile:

scale9Grid is not supported yet, but it would be valuable

Oh okay :confused:

Thanks for the info ! i’ll try to do it by hand then ^^.

In case it helps, here’s one way to do it.

Thank you :slight_smile:

I was trying to trace where the render code would be for (what I assume is) IBitmapData where it’s called after being set to dirty once the scale9Grid mode or other parameter is set.

Are there any high level notes/thoughts on how difficult would this be to implement for html5 target?


We have support for scale9Grid now in OpenFL :slight_smile:

Still some kinks though so take a look and see how it is working for you :slight_smile:

Hi there

The scale9grid working for vectors but unfortunately not working for bitmaps or bitmapfill graphics
I tried on Flash, Windows, HTML, and Hashline.

var bd = Assets.getBitmapData("rect-skin");
var scale9Grid = new Rectangle(10, 10, 12, 12);

// no scale bitmap
var bmp = new Bitmap(bd);
// scale-grid bitmap
var bmp = new Bitmap(bd);
bmp.scale9Grid = scale9Grid
bmp.x = 48;
bmp.width = 128;
bmp.height = 128;
// scale-grid shape
var shape = new Shape();;, 0, bd.width, bd.height);;
shape.scale9Grid = scale9Grid;
shape.x = 200;
shape.width = 128;
shape.height = 128;


Thanks for reading and helps.

I think for nine slice, you have to draw the bitmap data into a shape for each of the nine sections separately before assigning the scale9grid. Something like:

var shape = new Shape();
// top row;, 0, scale9Grid.x, scale9Grid.y);;;, 0, scale9Grid.width, scale9Grid.y);;;, 0, bd.width - scale9Grid.right, scale9Grid.y);;

// center;, scale9Grid.y, scale9Grid.x, scale9Grid.height);;;, scale9Grid.y, scale9Grid.width, scale9Grid.height);;;, scale9Grid.y, bd.width - scale9Grid.right, scale9Grid.height);;

// bottom;, scale9Grid.bottom, scale9Grid.x, bd.height - scale9Grid.bottom);;;, scale9Grid.bottom, scale9Grid.width, bd.height - scale9Grid.bottom);;;, scale9Grid.bottom, bd.width - scale9Grid.right, bd.height - scale9Grid.bottom);;

// assign the 9 slice rect
shape.scale9Grid = scale9Grid;
1 Like

Thanks Tamar. May I try the manual solution for slicing for this.

The better way

// scale grid shape
var shape = new Shape();
var cols:Array<Float> = [scale9Grid.left, scale9Grid.right, bitmapData.width];
var rows:Array<Float> = [, scale9Grid.bottom, bitmapData.height];
var left:Float = 0;
for (i in 0...3) {
  var top:Float = 0;
  for (j in 0...3) {;, top, cols[i] - left, rows[j] - top);;
    top = rows[j];
  left = cols[i];
shape.scale9Grid = scale9Grid;
shape.x = 200;
shape.width = 128;
shape.height = 128;