How to embed and display a png with FlashDevelop, Haxe and Swfmill
-
12-09-2019 - |
Question
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?
Solution
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.
OTHER TIPS
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
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.
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 { }