Question

I have an animation of a fireball. I have a choice of either using bitmaps (preferable since it makes my swf run a little smoother) or using a large group of objects (10-20 different drawings). I made it using the Deco Tool and it looks awesome!

Anyhow, it's quite annoying to make a new one. Plus when I tried to make a new one it just didn't look quite as good as my first one. I'm planning on making several different colors of fireballs. It would be extremely nice if I could somehow filter the colors of the entire symbol fireball1, but I'm struggling to do so.

I tried the following code, but for whatever reason, it just made my fireballs disappear completely. I may be getting confused because I'm adding all these new childs of my Fireball1 class to my arrays. Also, here is a link to the picture of my timeline, I think it might help understand what my fireball looks like http://tinypic.com/view.php?pic=fd7oyh&s=5.

private var fireball1:Fireball1;
private var gameTimer:Timer;
private var army1:Array; //included the arrays in case it effects it somehow
private var colorFilter:ColorMatrixFilter = new ColorMatrixFilter(colorMatrix);
private var colorMatrix:Array = new Array(
        [[0, 0, 1, 0, 0], 
        [0, 1, 0, 0, 0], 
        [1, 0, 0, 0, 0],
        [0, 0, 0, 1, 0]]);

public function PlayScreen(){
    army1 = new Array();
    var newFireball1 = new Fireball1( -100, 0 );
    army1.push(newFireball1);
    addChild(newFireball1);

    gameTimer = new Timer(50);
    gameTimer.start();
    addEventListener(TimerEvent.TIMER, onTick)
}

public function onTick():void
{
    var newFireball1:Fireball1 = new Fireball1( randomX, -15 );
newFireball1.filters = [colorFilter];
    army1.push( newFireball1 );
addChild( newFireball1 );
}
Was it helpful?

Solution

You need to define your matrix array before you instantiate the ColorMatrixFilter object. Also, ColorMatrixFilter expects a one dimensional array. See documentation which recommends a syntax using concat which seems to do the trick.

Try updating your code with the following:

// Matrix should be a one dimensional array
var colorMatrix:Array = new Array();
colorMatrix = colorMatrix.concat([0, 0, 1, 0, 0]), 
colorMatrix = colorMatrix.concat([0, 1, 0, 0, 0]), 
colorMatrix = colorMatrix.concat([1, 0, 0, 0, 0]),
colorMatrix = colorMatrix.concat([0, 0, 0, 1, 0]);

// Matrix needs to be defined before it's added to the ColorMatrixFilter
var colorFilter:ColorMatrixFilter = new ColorMatrixFilter(colorMatrix);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top