views:

1204

answers:

2

I am having trouble getting a png file to display in a simple Flash application I am building using Haxe and FlashDevelop.

Step taken

  • Added the png file to my project.
  • Added the png to the library
  • Set the option to embed as a bitmap
  • Set an Id for the object "PlayerBitmap"
  • Verified that the xml generated looks correct

I then try to display the embedded image:

var bitmap:Bitmap;
bitmap = new PlayerBitmap();
bitmap.x = 200;
bitmap.y = 200; 
addChild(bitmap);

The code compiles and generates a swf file but the image is not shown. Any pointers?

A: 

what do you get when you trace

  • bitmap
  • bitmap.bitmapData.rect
  • some random pixels with bitmap.bitmapData.getPixel

update 1: is your PNG maybe interlaced, or anything else like that? swfmill has problems with interlaced images, if i remember well ...

back2dos
Here are the traces:Bitmap: [object Bitmap]bitmap.bitmapData.rect: (x=0, y=0, w=20, h=20)bitmap.bitmapData.getPixel(5, 5): 0The getPixel is not what I would expect. It is black when the source at that point is red.I had a black background and when I changed it to white I can now see a black square where my image should be.For some reason it is loading a black image and not the actual image.
Alex Jeffery
+1  A: 

I have solved the issue by creating two simple test projects to load an image. The first worked and the second failed. There was one difference between the projects one had a package.

The working project my Main does not have a package it is compiled like this -main Main

The failing project is identical except the main is in a package and it compiles like this -main org.alexjeffery.Main

To get the image to load when my main was in the org.alexjeffery package I set the image name to org.alexjeffery.PlayerBitmap instead of PlayerBitmap.

I have now written a tutorial on how to embed images using FlashDevelop and Haxe.

Alex Jeffery