Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/462.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 Actionscript 3-脚本库_Actionscript 3_Mxmlc_Swc_Compc - Fatal编程技术网

Actionscript 3 Actionscript 3-脚本库

Actionscript 3 Actionscript 3-脚本库,actionscript-3,mxmlc,swc,compc,Actionscript 3,Mxmlc,Swc,Compc,我试图手动加载swc构建的结果swf。由于我的特殊环境,我们需要将类定义分离到SWC中(在有意义的地方),以从输出SWF中删除冗余代码 简而言之,我正在使用compc构建的swf中定义一个类(LibA)。我将它编译成swc和目录格式,这样我就可以轻松地从目录中提取library.swf以在运行时加载(外部链接),并使用swc从使用Flash CS5或mxmlc构建的任何swf中编译出来 LibA.as: package { public class LibA {

我试图手动加载swc构建的结果swf。由于我的特殊环境,我们需要将类定义分离到SWC中(在有意义的地方),以从输出SWF中删除冗余代码

简而言之,我正在使用
compc
构建的swf中定义一个类(
LibA
)。我将它编译成swc和目录格式,这样我就可以轻松地从目录中提取library.swf以在运行时加载(外部链接),并使用swc从使用Flash CS5或
mxmlc
构建的任何swf中编译出来

LibA.as

package
{
    public class LibA
    {
        public function LibA()
        {
            trace("*** LibA()");
        }
    }
}
package
{
    import flash.display.Loader;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.net.URLRequest;
    import flash.system.LoaderContext;

    public class Main extends Sprite
    {
        private var self:Main;
        private var context:LoaderContext;

        public function Main()
        {
            var l:Loader = new Loader();
            self = this;

            l.contentLoaderInfo.addEventListener(Event.COMPLETE, function(e:Event) {
                self.addChild(l.content);

                var liba:LibA = new LibA();
            });
            l.load(new URLRequest("./libs/build/liba.swf"));
        }
    }
}
Main.as

package
{
    public class LibA
    {
        public function LibA()
        {
            trace("*** LibA()");
        }
    }
}
package
{
    import flash.display.Loader;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.net.URLRequest;
    import flash.system.LoaderContext;

    public class Main extends Sprite
    {
        private var self:Main;
        private var context:LoaderContext;

        public function Main()
        {
            var l:Loader = new Loader();
            self = this;

            l.contentLoaderInfo.addEventListener(Event.COMPLETE, function(e:Event) {
                self.addChild(l.content);

                var liba:LibA = new LibA();
            });
            l.load(new URLRequest("./libs/build/liba.swf"));
        }
    }
}
我使用

compc-output libs/build/liba.swc-include sources libs/liba.as-debug=true

在构建
Main
(类直接链接到舞台)时,我在Flash CS5的AS3设置中设置了适当的链接

所有的东西都出版了,没有问题

但是,在运行时,找不到
VerifyError:Error\1014:LibA类。

我错过了什么?我希望能够从我的
Main.swf
加载和使用
liba.swf
中定义的类

完整跟踪转储:

verify Function/<anonymous>()
                        stack:
                        scope: [global Object$ flash.events::EventDispatcher$ flash.display::DisplayObject$ flash.display::InteractiveObject$ flash.display::DisplayObjectContainer$ flash.display::Sprite$ Main$ Main Main] 
                         locals: Object flash.events::Event? * 
  0:getlex 4
                        stack: Main?
                        scope: [global Object$ flash.events::EventDispatcher$ flash.display::DisplayObject$ flash.display::InteractiveObject$ flash.display::DisplayObjectContainer$ flash.display::Sprite$ Main$ Main Main] 
                         locals: Object flash.events::Event? * 
  2:getlex 7
                        stack: Main? flash.display::Loader?
                        scope: [global Object$ flash.events::EventDispatcher$ flash.display::DisplayObject$ flash.display::InteractiveObject$ flash.display::DisplayObjectContainer$ flash.display::Sprite$ Main$ Main Main] 
                         locals: Object flash.events::Event? * 
  4:getproperty content
                        stack: Main? flash.display::DisplayObject?
                        scope: [global Object$ flash.events::EventDispatcher$ flash.display::DisplayObject$ flash.display::InteractiveObject$ flash.display::DisplayObjectContainer$ flash.display::Sprite$ Main$ Main Main] 
                         locals: Object flash.events::Event? * 
  6:callpropvoid addChild 1
                        stack:
                        scope: [global Object$ flash.events::EventDispatcher$ flash.display::DisplayObject$ flash.display::InteractiveObject$ flash.display::DisplayObjectContainer$ flash.display::Sprite$ Main$ Main Main] 
                         locals: Object flash.events::Event? * 
  9:findpropstrict LibA
                        stack: Object
                        scope: [global Object$ flash.events::EventDispatcher$ flash.display::DisplayObject$ flash.display::InteractiveObject$ flash.display::DisplayObjectContainer$ flash.display::Sprite$ Main$ Main Main] 
                         locals: Object flash.events::Event? * 
  11:constructprop 10 0
                        stack: *
                        scope: [global Object$ flash.events::EventDispatcher$ flash.display::DisplayObject$ flash.display::InteractiveObject$ flash.display::DisplayObjectContainer$ flash.display::Sprite$ Main$ Main Main] 
                         locals: Object flash.events::Event? * 
  14:coerce LibA
VerifyError: Error #1014: Class LibA could not be found.
验证函数/()
堆栈:
作用域:[全局对象$flash.events::EventDispatcher$flash.display::DisplayObject$flash.display::InteractiveObject$flash.display::DisplayObjectContainer$flash.display::Sprite$Main$Main]
局部变量:对象闪存。事件::事件?*
0:getlex 4
堆栈:主?
作用域:[全局对象$flash.events::EventDispatcher$flash.display::DisplayObject$flash.display::InteractiveObject$flash.display::DisplayObjectContainer$flash.display::Sprite$Main$Main]
局部变量:对象闪存。事件::事件?*
2:getlex 7
堆栈:主?flash.display::Loader?
作用域:[全局对象$flash.events::EventDispatcher$flash.display::DisplayObject$flash.display::InteractiveObject$flash.display::DisplayObjectContainer$flash.display::Sprite$Main$Main]
局部变量:对象闪存。事件::事件?*
4:getproperty内容
堆栈:主?flash.display::DisplayObject?
作用域:[全局对象$flash.events::EventDispatcher$flash.display::DisplayObject$flash.display::InteractiveObject$flash.display::DisplayObjectContainer$flash.display::Sprite$Main$Main]
局部变量:对象闪存。事件::事件?*
6:callpropvoid添加子项1
堆栈:
作用域:[全局对象$flash.events::EventDispatcher$flash.display::DisplayObject$flash.display::InteractiveObject$flash.display::DisplayObjectContainer$flash.display::Sprite$Main$Main]
局部变量:对象闪存。事件::事件?*
9:FindPropLiba
堆栈:对象
作用域:[全局对象$flash.events::EventDispatcher$flash.display::DisplayObject$flash.display::InteractiveObject$flash.display::DisplayObjectContainer$flash.display::Sprite$Main$Main]
局部变量:对象闪存。事件::事件?*
11:10.0
堆栈:*
作用域:[全局对象$flash.events::EventDispatcher$flash.display::DisplayObject$flash.display::InteractiveObject$flash.display::DisplayObjectContainer$flash.display::Sprite$Main$Main]
局部变量:对象闪存。事件::事件?*
14:强迫利巴
VerifyError:错误#1014:找不到类LibA。

liba在您的SWF加载之前不存在,因为您没有将其导入main

这意味着在编译时它不存在


Move
var liba:liba=new liba()编码到加载的swf根上的函数调用中,并在加载后调用函数
e.currentTarget.someFunc
如果要从swf加载类,需要执行以下操作(在事件处理程序中):

创建一个新的
c
应该为您提供
LibA
对象。您需要完整的类定义作为名称

如果我理解您试图做什么,我很确定您可以将SWC设置为嵌入一个外部库-也就是说,您可以获得代码完成,但不包括任何类,并且在运行时搜索SWC

编辑

只是尝试了一些你正在做的事情。在我上面的示例中,当您创建
c
时,如果您跟踪它,它将跟踪
LibA
。但是,如果显式引用它,您将得到所描述的错误。我认为这是因为Flash基本上与
LibA
的两个定义混淆了,一个是引用的定义,另一个是加载的定义,它们位于两个不同的应用程序域中

正如@turbosqel所描述的那样,用
LoaderContext
对象加载它:

var l:Loader = new Loader();
var context:LoaderContext = new LoaderContext( false, ApplicationDomain.currentDomain );
l.contentLoaderInfo.addEventListener(Event.COMPLETE, this._onLoadComplete );
l.load(new URLRequest("./libs/build/liba.swf"), context);

这对我来说是可行的,我现在可以显式地引用
LibA
类。

您的假设是正确的,这就是正在做的事情(linkage设置为external,我正在手动加载包含类定义的swf)。有趣的是,这在我正在使用的第三方运行时中可以正常工作,但在Flash中不能。我的完整用例实际上有点复杂,引入了跨swc定义的继承(即
LibB
extends
LibA
)。还有@turbosqelYes的道具,为我修复了它。如果@turbosqel没有添加答案(正如他首先建议的那样),我会接受这个答案-感谢您的帮助。我认为这将是一个问题,因为如果您需要跨swf中的类,您需要将类加载到同一个应用程序域。W