Copy link to clipboard
Copied
I used the library project to generate a swc, I modified it to zip, and after manually extracting, I got a swf file. I use URLLoader to load it. I can get this class using getDefinitionByName("com.demo.myClass"), but if I change the extension of this swc file to any other name, such as .scg, then use URLLoader to load it. The loading was successful.
On ios, select the debug status and limit the distribution of the temporary distribution, use getDefinitionByName ("com.demo.myClass") to get the class; on ios, select the final release package exported to the Apple App Store, use getDefinitionByName ( "com.demo.myClass") could not get the class, prompt #1065 error.
I found through testing that it is exported to the final distribution of the Apple App Store. When the file extension is swf or swc, the ByteArray obtained from the target.data of the URLLoader is much smaller than the load extension .scg.
How can I load a swf or swc file with a custom extension?
private function loadSWC():void
{
var loader:URLLoader = new URLLoader();
loader.addEventListener(flash.events.Event.COMPLETE,swcLoaded);
loader.dataFormat = URLLoaderDataFormat.BINARY;
// loader.load(new URLRequest("assets/testSWC.scg"));
loader.load(new URLRequest("assets/testSWC.swf"));
}
private function swcLoaded(e:flash.events.Event):void
{
var byte:ByteArray = e.target.data;
trace(byte.bytesAvailable);
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(flash.events.Event.COMPLETE,libReady);
var loaderContext:LoaderContext = new LoaderContext(false,ApplicationDomain.currentDomain);
loaderContext.allowCodeImport = true;
loader.loadBytes(byte,loaderContext);
}
private function libReady(e:flash.events.Event):void
{
try
{
var Cl1:Class = getDefinitionByName("com.demo.myClass") as Class;
}catch(e:ErrorEvent)
{
trace("get Class error:" + e.toString());
}
}