在ActionScript3的嵌入的位图 [英] Embed bitmap in ActionScript3

查看:183
本文介绍了在ActionScript3的嵌入的位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何可以嵌入一个位图在ActionScript 3中,并得到的BitmapData?

How can I embed a bitmap in Actionscript 3 and get the 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)
    }
}

我已经竭尽所能。如果我尝试实例化嵌入类(新BMClass(); )我得到这个错误:

I've tried everything. If I ever try to instantiate the embedded class (new BMClass();) I get this error:

类型错误:错误#1007:实例化尝试对非构造

如果我用

[内嵌(来源=资产/ helicopter1.png)私有静态无功BMClass:的​​BitmapData;

或类似的BitmapData东西为空。

or something similar the BitmapData is null.

编辑:

所以我想通了,嵌入的数据为空,但我想不出为什么。我做了什么错在嵌入?

So I figured out that the embedded data is null, but I can't figure out why. What did I do wrong in the embedding?

推荐答案

看起来,你是嵌入正确,如果你没有得到一个错误代码转换。您应该能够直接从位图得到的位图数据:

Looks like you are embedding correctly if you don't get an error transcoding. You should be able to get the bitmapData directly from the bitmap:

[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;

这篇关于在ActionScript3的嵌入的位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆