I’m porting over the companies framework from Flash to Haxe/OpenFL. I have a plugin system that use the Flash/Flex Embed tag for images and fonts.
[Embed(source = "../../../../assets/ic/button/button_default.png")]
public var Button_Default:Class;
Plus I know I can use the @:bitmap,@font,@sound and @file tag but I want to make sure this will work on other platforms as well. What is the best way to go about doing this?
Yeah, I think you can use @:bitmap
, let me know if you have an issue
Do all the flash embed tags work on other platforms?
They should, we implemented macros for the non-Flash targets so they could work similarly. I think the only thing is that on HTML5, we don’t preload assets that are defined this way, so I think there can be a delay until its available
1 Like
Okay, what if the assets are in another folder that isn’t the project well that work as well? I’m still getting null when I try to grab the class.
Here is the variable being setup
@:bitmap("…/_FRAMEWORK/Camber_Core_HX/assets/ic/button/button_default.png")
public var Button_Default : Class;
Here is me calling the class
var defaultState : Bitmap = new Bitmap(Type.createInstance(Button_Default, []));
I could be wrong, but I think these use class paths to resolve the file location, rather than being relative to the class file
I’ve also done this:
@:bitmap("../../../../assets/ic/button/button_default.png")
public var Button_Default : Class<Dynamic>;
Here is the class path layout:
I think it has to extend BitmapData
for the image
Try it on the Flash target first, once it’s working, try it elsewhere and see what happens
1 Like
Oh word! That worked! Here is my code!
package;
import openfl.Assets;
import openfl.display.Sprite;
import openfl.Lib;
import openfl.display.BitmapData;
@:bitmap("../_FRAMEWORK/Camber_Core_HX/assets/ic/button/button_default.png")
class Button_Default extends BitmapData { }
/**
* ...
* @author
*/
class Main extends Sprite
{
public function new()
{
super();
trace(Button_Default);
}
}