例如,现在我有一类称为Balls.as。在这里,我打开10个不同的球图像。你知道,像这样的:
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")]
[Embed(source = "/ball2.png")]
现在的问题是,如果我产卵5球,这些球的图像会得到嵌入式5 * 5倍吧?纠正我,如果我错了!所以,我虽然,我不能有一个ballimageloading类?加载这些图像一次,然后在Balls.as我可以加载什么球我想要的时刻?
The problem is that if I spawn 5 balls, these balls images gonna get embeded 5 * 5 times right? Correct me if I'm wrong! So I though, can't I have a ballimageloading class? That loads these images once, and then in Balls.as I can load whatever ball i want for the moment?
最好的做法是有一个资产
这将包含静态嵌入式图像,像这样的类:
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.
上一篇:MSMQ产生错误:工作组安装的计算机不支持该操作/用户的内部消息队列证书不存在不存在、队列、不支持、工作组
下一篇:UserPrincipal.GetGroups与UserPrincipal.GetAuthorizationGroups?UserPrincipal、GetGroups、GetAuthorizatio