Embedding multiple images in one Class file, in Haxe 3

171 Views Asked by At

I'm trying to embed several images (the manual way with @:bitmap(...) for each PNGs) in the same class file.

But, when I come to use the PNG, I keep getting Class not found : assets._NameOfImageClass_

Do I need to import the same-named Class as the *.hx file they're all tossed in, first?

(Example: If they are all defined in: assets/Assets.hx, do I need to import assets.Assets; before I can use new ICON_FILE(); or should I be able to just use import assets.ICON_FILE;?)

I'm using FlashDevelop, this is to target Flash.

(Note: I would prefer not to use an OpenFL solution for this)

1

There are 1 best solutions below

0
On

You just need the line import assets.Assets;

The class with assets.

package mypack ;

import flash.media.Sound;

@:sound("assets/sound/Hit_Hurt.wav") class Hit_Hurt extends flash.media.Sound { }
@:sound("assets/sound/Jump2.wav") class Jump extends flash.media.Sound { }
@:sound("assets/sound/Laser_Shoot.wav") class Laser_Shoot extends flash.media.Sound { }

class SoundLib
{
    private static var _sounds:Array<Sound> = [ new Hit_Hurt(), new Jump(), new Laser_Shoot() ];


    public static function play( index:Int ):Void
    {
        _sounds[ index ].play();
    }

}

The main class.

package ;

import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.Lib;
import flash.media.Sound;
import mypack.SoundLib;

class Main 
{


    static function main() 
    {
        var stage = Lib.current.stage;
        stage.scaleMode = StageScaleMode.NO_SCALE;
        stage.align = StageAlign.TOP_LEFT;

        var tmp:Sound = new Laser_Shoot();
        tmp.play();
    }

}