AS3 无法在 Loader 上找到加载方法

AS3 can't find the load method on a Loader

我正在尝试使用 AS3 this tutorial 从互联网加载图像。当我尝试编译应用程序时出现以下错误:

Call a possibly undefined method load through a reference with static type Loader.

      my_loader.load(where, loaderContext);
                  ^

这是我使用的代码:

package {
    import flash.system.ApplicationDomain;
    import flash.system.SecurityDomain;
    import flash.net.URLRequest;
    import flash.system.LoaderContext;
    import flash.display.Loader;
    import flash.events.*;
    import flash.external.ExternalInterface;
    import flash.display.Sprite;

    public class Loader extends Sprite {

        public function Loader() {
            var where:URLRequest = new URLRequest("image_from_web.png");
            var loaderContext:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain, null);
            var my_loader:Loader = new Loader();
            my_loader.load(where, loaderContext);
            addChild(my_loader);
        }
    }
}
    
                      

在此页面中 compilerErrors(ErrorCode = 1061) 说当我尝试调用不存在的方法时会发生这种情况。

我正在使用 Ubuntu 14.10 并使用使用 flex 编译器的 ProjectSprout 进行编译。

您的问题是命名空间冲突(不明确的 class 名称)。您发布的 class 名为 Loader,但您尝试导入另一个 Loader class。现在你引用 Loader 时,AS3 不知道你指的是什么。所以它正在为您的自定义 Loader class(不存在)寻找 load 方法。

要解决此问题,请将您的自定义 class 重命名为更明确的名称(MyImageLoader 可能,或其他)- 或者在引用时使用完全限定的 class 路径显示包加载器。例如

var my_loader:flash.display.Loader = new flash.display.Loader();