Reputation: 578
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).
Upvotes: 2
Views: 3779
Reputation: 66
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)
Upvotes: 0
Reputation: 1863
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
Upvotes: 0
Reputation: 578
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)
Upvotes: 1
Reputation: 4432
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!
Upvotes: 4