在ActionScript3中嵌入位图

Hop*_*Abc 2 embed actionscript bitmap actionscript-3

如何在Actionscript 3中嵌入位图并获取BitmapData?

public class MyGame extends Sprite {
    [EMBED(source="Assets/helicopter1.png")] private static var BMClass:Class;
    public function MyGame() {
        var BM:Bitmap = new BMClass();
        var BMData:BitmapData = new BitmapData(BM.width, BM.height);
        BMData.draw(BM)
    }
}
Run Code Online (Sandbox Code Playgroud)

我已经尝试了一切.如果我尝试实例化嵌入式类(new BMClass();),我会收到此错误:

TypeError: Error #1007: Instantiation attempted on a non-constructor..

如果我使用

[EMBED(source="Assets/helicopter1.png")] private static var BMClass:BitmapData;

或类似的东西BitmapData为null.

编辑:

所以我发现嵌入数据是空的,但我无法弄清楚原因.我在嵌入中做错了什么?

Nei*_*eil 17

如果您没有收到错误转码,看起来您正确嵌入.您应该能够直接从位图获取bitmapData:

[Embed(source="picture.jpg")]
private var Picture:Class;

// create a bitmap of the embedded
var pic:Bitmap = new Picture();

// add to display list
addChild(pic);

// if you need to get the bitmapData for something else
var bitmapData:BitmapData = pic.bitmapData;
Run Code Online (Sandbox Code Playgroud)