Reputation: 10823
var subimage = new Bitmap();
subimage.bitmapData = new BitmapData(25, 25, true, 0);
addChild(subimage);
From everything I've read, this should be transparent. I'm seeing a big black square. What could cause that?
Upvotes: 7
Views: 4717
Reputation: 17217
You can either create or pass BitmapData to the constructor of a new Bitmap object, or edit it by reference after it is created. Both options work:
package
{
//Imports
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
//Document Class
public class Main extends Sprite
{
//Constructor
public function Main()
{
var bmpData:BitmapData = new BitmapData(200, 200, true, 0x5500FF00);
var bmp:Bitmap = new Bitmap(bmpData);
addChild(bmp);
var bmp2:Bitmap = new Bitmap();
bmp2.bitmapData = new BitmapData(200, 200, true, 0x55FF0000);
bmp2.x = bmp2.y = 200;
addChild(bmp2);
}
}
}
Upvotes: 3
Reputation: 4530
use this
new BitmapData(25, 25, true, 0x00000000);
instead of
new BitmapData(25, 25, true, 0);
0xFF000000 is black(0x000000) with alpha equal to 1
0x00000000 is black(0x000000) with alpha equal to 0
Here is a nice explanation how colors & alpha work: http://myflex.wordpress.com/2007/09/07/about-hex-color-codes-in-flex-as3/
//EDIT:
Dennis Krøger and strille are right, 0x00000000 == 0. Looks like the problem is somewhere else, not in the code you pasted in.
Upvotes: 13
Reputation: 416
It makes no sense: I tried the following code:
package
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
public class TestBitMap extends Sprite
{
public function TestBitMap() {
var imageYellow:Bitmap = new Bitmap(new BitmapData(100, 100, true, 0xFFFFFF00));
var imageTransparent:Bitmap = new Bitmap(new BitmapData(100, 100, true, 0));
var imageSemiTransparent:Bitmap = new Bitmap(new BitmapData(100, 100, true, 0x99000000));
imageTransparent.x = 25;
imageTransparent.y = 25;
imageSemiTransparent.x = 50;
imageSemiTransparent.y = 50;
addChild(imageYellow);
addChild(imageTransparent);
addChild(imageSemiTransparent);
}
}
}
And I got a yellow box with a semitransparent black box over it. The "imageTransparent" was completely invisible.
I also tried your method with creating the BitMap first, then changing the bitmapData. No difference, still invisible.
San.chez: 0 is equal to 0x00000000, no matter what. It is an unsigned integer, ActionScript doesn't magically change it. Your link is good though.
Upvotes: 2
Reputation: 8996
ActionScript uses a 32-bit hexadecimal numbers to represent color values with transparency. ARGB colors as 32 bit variables are specified by 4 groups of 8 bits each / or 2 hex each:
In binary: AAAAAAAA RRRRRRRR GGGGGGGG BBBBBBBB
In hex: AA RR GG BB
A represents the alpha value (transparency), R is rd, G is green, B is blue. Each group defines intensity of each of the colors channels, A is alpha, R is red, G is green, B is blue. Full intensity on the alpha channel means no alpha (FF) and no intensity (00) means full alpha. So a transparent pixel color value is 0x00rrggbb.
Upvotes: 3