Matti,我相信 Lukasz 的评论是正确的,因为它是一个安全错误。
您可以通过嵌入 Movie.swf 而不是使用加载程序来避免此安全错误。如果您这样做,那么在编译时,Movie.swf 需要位于 Game.as 文件旁边,它将包含在 Game.swf 中(无需同时提供这两个文件,只需 Game.swf)。
语法是:
package
{
import flash.display.Sprite;
public class Game extends Sprite
{
[Embed(source="MyMovie.swf")]
private var myMovieClass:Class;
private var myMovie:DisplayObject;
public function Game():void
{
myMovie = new myMovieClass();
// Technically myMovie is now a Loader, and once
// it's loaded, it'll have .content that's a
// MovieClipLoaderAsset, and .content.getChildAt(0)
// will be your MyMovie.swf main timeline.
}
}
}
或者,如果您将其嵌入为 mimeType="application/octet-stream",您可以获取 SWF 的字节并在现有 Loader 的 .loadBytes() 方法中使用它:
package
{
import flash.display.Sprite;
import flash.utils.ByteArray;
public class Game extends Sprite
{
[Embed(source="MyMovie.swf", mimeType="application/octet-stream")]
private var movieBytes:Class;
private var myMovie:DisplayObject;
public function Game():void
{
// Treat this loader the same as your current loader,
// but don't call .load(url), call loadbytes():
var l:Loader = new Loader();
l.loadBytes(new movieBytes() as ByteArray);
}
}
}