0

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?

Alex Jeffery
  • 187
  • 3
  • 12

4 Answers4

2

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
  • 187
  • 3
  • 12
0

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 ...

greetz

back2dos

back2dos
  • 15,588
  • 34
  • 50
  • Here are the traces: Bitmap: [object Bitmap] bitmap.bitmapData.rect: (x=0, y=0, w=20, h=20) bitmap.bitmapData.getPixel(5, 5): 0 The 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 Jul 12 '09 at 09:27
0

Simple, open the directory of the project, then go to the source folder, and then paste the *.png files there. They will automatically be detected by FlashDevelop.

Anony Mous
  • 23
  • 2
0

You might want to check out this page on the Haxe manual:
http://haxe.org/manual/target-flash-resources.html

Basically you need:

@:bitmap("relative/path/to/myfile.png") 
class MyBitmapData extends BitmapData { }
Mark Knol
  • 9,663
  • 3
  • 29
  • 44