0

I'm trying to create a game in which after you click on an object, the object glows. When I embed an image and pass it through a bitmap, it works fine, like this:

   package  
    {
    import org.flixel.*;    

    public class HelloWorld extends FlxState

{

    [Embed(source = "pics/Cancer.png")] private var cancerIMG:Class;
    private var cancer:FlxSprite; 

    private var title_text:FlxText;     

    public function HelloWorld() 
    {
    }       

    override public function create():void
    {           

        /**
         * Glow method test
         */  
        //Start Test
        var bigbitmap:BitmapData = new BitmapData(320, 288, true, 0x00000000);
        bigbitmap.copyPixels(Bitmap(new cancerIMG).bitmapData, new Rectangle(0, 0, 160, 288), new Point(16, 16), null, null, true);

        cancer = new FlxSprite;
        cancer.pixels = bigbitmap;

        add(cancer);        
        //End Test

    }

    override public function update():void
    {

        super.update();          
    }       

}   
} 

However, whenever I try to pass a class sprite using that same method, like this:

        _bx = new box(120, 120);            

        var bigbitmap:BitmapData = new BitmapData(320, 288, true, 0x00000000);
        bigbitmap.copyPixels(Bitmap(_bx.pixels).bitmapData, new Rectangle(0, 0, 160, 288), new Point(16, 16), null, null, true);

        _bx.pixels = bigbitmap;         
        add(_bx);

I call the box like this:

    public var _bx:box; 

Which, itself is a FlxExtendedSprite (reverted it back to a regular FlxSprite though for the test). When I try that, I get the error of:

Error #1034: Type Coercion failed: cannot convert flash.display::BitmapData@3960701 to flash.display.Bitmap.

Is there an way I can fix this effect and get it to work with classes like this?

Thanks in advance!

JeffryHouser
  • 39,401
  • 4
  • 38
  • 59
xhunterko
  • 49
  • 7
  • It sounds like you're trying to use BitmapData where a bitMap is required. However, based on your code; I'm not sure which line is throwing the error and I'm not familiar with the Flixel classes. – JeffryHouser Jun 17 '12 at 01:59
  • Which brings me to a possible solution. Is there any way that one can be converted to the other? – xhunterko Jun 17 '12 at 02:39
  • Yes, you can get the BitMapData from a BitMap using the bitMapData property. http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Bitmap.html#bitmapData . You can create a BitMap from BitMapData by specifying the data as a constructor argument http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Bitmap.html#Bitmap() – JeffryHouser Jun 17 '12 at 02:57
  • Okay. I'll try and give that a shot to see if it works. – xhunterko Jun 17 '12 at 03:38
  • Anything else I can do to try and get it to work? – xhunterko Jun 17 '12 at 03:56
  • The Bitmap vs BitmapData thing is the only thing that comes to mind for me, too. Did you get a new error, same old error, or did it simply not work? – Mar Jun 17 '12 at 05:59
  • I've not done that method yet. – xhunterko Jun 17 '12 at 19:38

2 Answers2

1

_bx.pixels is a BitmapData so I think it's as simple as this. Works in my test setup at least.

bigbitmap.copyPixels(_bx.pixels, new Rectangle(0, 0, 160, 288), new Point(16, 16), null, null, true);
WgFunstorm
  • 148
  • 1
  • 10
0

Really not that hard to find..

//This goes in the package, at the top of your .as
import flash.filters.GlowFilter;

//This goes in your class
var myFilter:GlowFilter = new GlowFilter(0xffffff, 1, 1.5, 1.5, 30, 4); //(color, alpha, blurX, blurY, strength, quality);

//This goes wherever you want to apply this method
myMC.filters = [myFilter];
paddotk
  • 1,359
  • 17
  • 31
  • The one who downvoted, please tell me why you did this so I can take the suggestion into account :) – paddotk Jun 18 '12 at 10:35
  • Ok, but this is the Adobe documentation, it doesn't just go down anytime. But I get your point. The reason I did it this way though, is that while answering, I'm also saying the OP should look it up first before posting a question like this on SO. – paddotk Jun 19 '12 at 18:09