2

When I use it, the only thing that is filled is a white rectangle, doesn't matter the parameter. This is what I do:

var map:Bitmap = new Bitmap (new BitmapData(200,200))
map.bitmapData.fillRect(new Rectangle(0,0,100,100),0xFF0000)

A 100x100 rectangle is added to the bitmap, but it is always a white shape. I want it to be red, as set in the parameter (0xFF0000).

Lucas
  • 558
  • 11
  • 28

5 Answers5

4

The color argument should be in ARGB format, meaning the first value is the alpha. Not sure what happens when you send in a 3 byte value instead of a 4. Try 0xFFFF0000 instead.

Hope that helps!

Jonatan Hedborg
  • 4,382
  • 21
  • 30
  • My experience is it treats `0xFF0000` like `0x00FF0000`, which is 0% opacity red, ie nothing. How he got white out of that I'm unsure. – Mar Feb 08 '12 at 17:28
2
map.bitmapData.fillRect(new Rectangle(0,0,100,100),0xFFFF0000)
Benny
  • 2,250
  • 4
  • 26
  • 39
1

Discovered the answer already. I was parsing a RGB parameter for the color, while I should be passing an ARGB.

Thus, because I want red, I should write 0xFFFF0000, instead of 0xFF0000

var map:Bitmap = new Bitmap (new BitmapData(200,200))
map.bitmapData.fillRect(new Rectangle(0,0,100,100),0xFFFF0000)
Lucas
  • 558
  • 11
  • 28
0

If you use a BitmapData that is not transparent you can define the color with a regular hex number.

var map:Bitmap = new Bitmap (new BitmapData(200,200,false))
map.bitmapData.fillRect(new Rectangle(0,0,100,100),0xFF0000)

But if you use a transparent BitmapData you must use the ARGB format:

var map:Bitmap = new Bitmap (new BitmapData(200,200))
map.bitmapData.fillRect(new Rectangle(0,0,100,100),0xFFFF0000)
0
import gs.TweenMax;
import fl.transitions.easing.*;
import flash.display.Bitmap;
import flash.display.BitmapData;
var container:Sprite = new Sprite();
var b:Box = new Box();
b.x = b.y = 0;
container.addChild(b);
var bmd:BitmapData = new BitmapData(stage.stageWidth, stage.stageHeight);
var bmp:Bitmap = new Bitmap(bmd);
this.addChild(bmp);
TweenMax.to(b, 1.5, {x: 525, y: 375, ease: Regular.easeOut, onComplete: doComplete});
function doComplete():void
{
    this.removeEventListener(Event.ENTER_FRAME, drawAnimation);
}
this.addEventListener(Event.ENTER_FRAME, drawAnimation);
function drawAnimation(evt:Event):void
{
    bmd.fillRect(bmd.rect, 0);
    bmd.draw(container);
}

bmd.fillRect(bmd.rect, 0);

it basically fill's the area of the BitmapData object with a transparency by using the size of the BitmapData's rectangle to define the area to fill. A VERY handy little trick to know when working with BitmapData. If you take out this line of code you will see that the box is still moving across but leaving "streaks" behind it.

for more information you can go here
http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00000787.html

Swati Singh
  • 1,863
  • 3
  • 19
  • 40