【发布时间】:2011-12-06 10:47:15
【问题描述】:
我对编程很生疏,不了解内部加载和外部加载之间的区别。使用 Flash Develop 制作的游戏,我的所有资产都将包含在包中。它们数量不多(20 张图片和小 mp3 ~2 MB)。使用下面的代码加载我的资产有什么问题?或者为什么我必须创建一个带有等待计时器的 URL 加载器?任何 cmets 将不胜感激。
public class ImageLoader
{
private var alImages:Array = new Array;
public function ImageLoader()
{
[Embed(source = "../lib/greenbutton.png")]
var imgGreenButton:Class;
alImages.push(["imgGreenButton", imgGreenButton]);
[Embed(source = "../lib/tray.jpg")]
var imgTray:Class;
alImages.push(["imgTray", imgTray]);
}
public function getBitmap (search:String):Bitmap {
// Create Cyan square for load fails
var tempData:BitmapData = new BitmapData(40, 40, false, 0x000FFFF);
var tempBitmap:Bitmap = new Bitmap (tempData);
for (var i:int = 0; i < alImages.length; i++) {
if (alImages[i][0] == search) {
tempBitmap = new alImages[i][1];
}
}
return tempBitmap;
}
}
【问题讨论】:
-
我不确定我是否理解您的问题:)。您没有在此示例中加载您的资产。您正在嵌入它们(这意味着它们在编译时被编译到您的 swf 中,并且可以直接从您的代码中访问)。要加载外部资产,您需要创建 Loader 类实例、创建 URLRequest 对象等。然后您需要实现一些事件处理程序。至于您的代码 - 使用 Dictionary 而不是 Array 来存储位图。字典会让您直接访问位图,而不是遍历所有项目。
-
感谢 rincewind。我会查字典。
标签: actionscript-3