AS3 Embed images class and then get these images into another class?

前端 未结 2 1247
被撕碎了的回忆
被撕碎了的回忆 2021-01-18 15:28

For example, right now I have a class called \"Balls.as\". Here I load 10 different balls-images. You know, like this:

[Embed(source = \"/ball1.png\")]
[Emb         


        
2条回答
  •  清酒与你
    2021-01-18 15:38

    The best practice is to have an Assets class which will contain static embeded images, like this:

    [Embed(source="ball1.png")]
    public static var BallImage1:Class;
    

    Then all you'll have to do is declare a variable for your loaded Bitmap and use it, like so:

    protected var mBall1:Bitmap = new Assets.BallImage1() as Bitmap;
    

    This will create a Bitmap instance of your loaded image and you can then add it to the display list. Loading will happen only once per image and you'll have all your images at your fingertips, accessible from every class you have.

提交回复
热议问题