I think it's coming out blue because your using SUBTRACT when applying the cooling filter. Thus it subtracts all other colors and adds that blue.

Karl

Sent from losPhone

On Sep 3, 2010, at 7:32 AM, George Jones <flashergeo...@hotmail.com> wrote:


Hi;
I think I've done my homework on this, but I can find no answers. Is it possible, using BitmapData, to make part--and only part--of a bitmap transparent? I'm presuming the answer is "no". If that is the case, would you be so kind as to inform me so that I quit beating my head against the wall? I've asked the following question on about 5 forums and nobody has answered it, which I presume means it's over most people's heads...but certainly not this list. The net effect which I'm trying to create is programmically created fire that burns over a background image I select. What I now have is such fire over a black background (or any other color I choose), not over a jpg, for example.

I'm trying to tweak a script I found online to work for my application.
The problem I am having is to make a certain part of the bitmap that
is  created by code transparent...but only a certain part of it. The
code  has the following:

_fire = new BitmapData(865, 92, false, 0xffffff);

Note
the alpha flag must be set to false, which is the source of my problem,
or nothing prints to screen at all. I need to make certain pixels
transparent. _fire is added to the stage and then called thus:

_fire.paletteMap(_grey, _grey.rect, ZERO_POINT, _redArray, _greenArray, _blueArray, _alphaArray);

at the end of the script. The colors for the arrays are created thusly:

private function _createPalette(idx:int):void {
_redArray = [];
_greenArray = [];
_blueArray = [];
_alphaArray = [];
for (var i:int = 0; i < 256; i++) {
var gp:int = new int();
gp = _fireColor.getPixel(i, 0);
if (gp < 1050112)
{
_redArray.push(255);
_alphaArray.push(255);
} else {
_redArray.push(gp);
_alphaArray.push(0);
}
_greenArray.push(0);
_blueArray.push(0);
}
}

I
added that if clause to capture when the color is black because that's
where I need to make it transparent. The problem is that where I need it
to be transparent, it's blue (why blue I don't know). Is there any way
to make it transparent? The entire code follows.
TIA,
George



package {
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.BlendMode;
import flash.display.DisplayObject;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.display.Sprite;
import flash.display.StageQuality;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.filters.ColorMatrixFilter;
import flash.filters.ConvolutionFilter;
import flash.geom.ColorTransform;
import flash.geom.Point;
import flash.system.LoaderContext;
import flash.net.SharedObject;
import flash.net.URLRequest;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;

[SWF(width=465, height=92, backgroundColor=0xffffff, frameRate=30)]

public class Fire extends Sprite {

private static const ZERO_POINT:Point = new Point();

private var _fireColor:BitmapData;
private var _currentFireColor:int;

private var _canvas:Sprite;
private var _grey:BitmapData;
private var _spread:ConvolutionFilter;
private var _cooling:BitmapData;
private var _color:ColorMatrixFilter;
private var _offset:Array;
private var _fire:BitmapData;
private var _redArray:Array;
private var _zeroArray:Array;
private var _greenArray:Array;
private var _blueArray:Array;
private var _alphaArray:Array;

public function Fire() {
//            stage.scaleMode = StageScaleMode.NO_SCALE;
//            stage.quality = StageQuality.LOW;
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.CO MPLETE, _onLoaded); loader.load(new URLRequest('images/fire-color.png'), new LoaderContext(true));
}

private function _onLoaded(e:Event):void {
_fireColor = Bitmap(LoaderInfo(e.target).loader.content).bitmap  Data;

_canvas = new Sprite();
_canvas.graphics.beginFill(0xffffff, 0);
_canvas.graphics.drawRect(0, 0, 865, 465);
_canvas.graphics.endFill();
_canvas.addChild(_createEmitter());

_grey = new BitmapData(865, 465, false, 0xffffff);
_spread = new ConvolutionFilter(3, 3, [0, 1, 0, 1, 1, 1, 0, 1, 0], 5);
_cooling = new BitmapData(865, 465, false, 0xffffff);
_offset = [new Point(), new Point()];
_fire = new BitmapData(865, 92, false, 0xffffff);
addChild(new Bitmap(_fire));

_createCooling(0.16);
_createPalette(_currentFireColor = 0);

addEventListener(Event.ENTER_FRAME, _update);
//            stage.addEventListener(MouseEvent.CLICK, _onClick);
}

private function _onClick(e:MouseEvent):void {
if (++_currentFireColor == int(_fireColor.height / 32)) {
_currentFireColor = 0;
}
_createPalette(_currentFireColor);
}

private function _createEmitter()isplayObject {
var tf:TextField = new TextField();
tf.selectable = false;
tf.autoSize = TextFieldAutoSize.LEFT;
tf.defaultTextFormat = new TextFormat('Verdana', 80, 0xffffff, true);
tf.text = '__________________________________________';
tf.x = (465 - tf.width) / 2;
tf.y = 0;
//            tf.y = (465 - tf.height) / 2;
return tf;
}

private function _createCooling(a:Number):void {
_color = new ColorMatrixFilter([
a, 0, 0, 0, 0,
0, a, 0, 0, 0,
0, 0, a, 0, 0,
0, 0, 0, 1, 0
]);
}

private function _createPalette(idx:int):void {
_redArray = [];
_greenArray = [];
_blueArray = [];
_alphaArray = [];
for (var i:int = 0; i < 256; i++) {
var gp:int = new int();
gp = _fireColor.getPixel(i, 0);
if (gp < 1050112)
{
_redArray.push(255);
_alphaArray.push(255);
_greenArray.push(255);
_blueArray.push(255);
} else {
_redArray.push(gp);
_alphaArray.push(0);
_greenArray.push(0);
_blueArray.push(0);
}
}
}

private function _update(e:Event):void {
_grey.draw(_canvas);
_grey.applyFilter(_grey, _grey.rect, ZERO_POINT, _spread);
_cooling.perlinNoise(50, 50, 2, 982374, false, false, 0, true, _offset);
_offset[0].x += 2.0;
_offset[1].y += 2.0;
_cooling.applyFilter(_cooling, _cooling.rect, ZERO_POINT, _color);
_grey.draw(_cooling, null, null, BlendMode.SUBTRACT);
_grey.scroll(0, -3);
_fire.paletteMap(_grey, _grey.rect, ZERO_POINT, _redArray, _greenArray, _blueArray, _alphaArray);
}
}
}
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to