Hi;
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.COMPLETE,
_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).bitmapData;
_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():DisplayObject {
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