我試圖加載swc生成swf手動生成。由於我的特定環境,我們需要將類定義分離到swcs(有意義的地方),以便從輸出swfs中刪除多餘的代碼。Actionscript 3 - 腳本庫
簡而言之,我在用compc
構建的swf中定義了一個類(LibA
)。我將它編譯爲swc和目錄格式,以便我可以輕鬆地從目錄中提取library.swf以在運行時加載(外部鏈接),並使用swc從任何使用Flash CS5或mxmlc
構建的swf編譯出來。
LibA.as:
package
{
public class LibA
{
public function LibA()
{
trace("*** LibA()");
}
}
}
Main.as:
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"));
}
}
}
我打造的深港西部通道/目錄的SWC與
compc -output libs/build/liba.swc -include-sources libs/LibA.as -debug=true
,我在構建Main
(直接鏈接到舞臺的類)時,在Flash CS5的AS3設置中設置了適當的鏈接。
一切發佈都沒有問題。
然而,在運行時我得到VerifyError: Error #1014: Class LibA could not be found.
缺少什麼我在這裏?我希望能夠加載和使用我的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.
何時拋出錯誤,運行之後甚至在加載外部SWF之後? – turbosqel 2012-01-17 06:58:06
在這個例子中,它引發了類的實例化。 – 2012-01-17 07:07:31
因此,如果主應用程序無法訪問,則會將外部SWF加載到錯誤的應用程序域。你如何加載liba.swf,你使用LoaderContext? – turbosqel 2012-01-17 07:59:10