I am using LoaderMax to load an external PNG and display it in many places so I use the following code to duplicate the image:
var cd:ContentDisplay = ContentDisplay(loader.getContent("name"));
var b1 = Bitmap(cd.rawContent);
var old = b1.bitmapData;
var bmp = new Bitmap(b1);
container.addChild(bmp);
The original image has a 50% on the alpha channel, but when I create the new bitmap from from the same bitmapData object, it does not preserve the alpha channel.
If I try to copy the alpha channel (see the code below; if I understand correctly, the alpha channel is copied from itself, to itself)- the transparency is on the new image , but the code throws an error…
bmp.copyChannel(old, new Rectangle(0, 0, old.width, old.height), new Point(), BitmapDataChannel.ALPHA, BitmapDataChannel.ALPHA);
Error:
ReferenceError: Error #1069: Property copyChannel not found on flash.display.Bitmap and there is no default value.
at barmask/frame1()
How can I duplicate a PNG and maintain the alpha transparency… preferably without the error?
P.s. Please forgive any obvious mistakes, I am a ActionScript Newb…
create your
BitmapDatainstance, passing 3 parameters to the constructor:new BitmapData(w, h, true),Booleanvalue is transparencyalso check the
transparentproperty of the sourceBitmapData