problems with loading embedded swf files in air ap

2019-04-16 02:14发布

问题:

I have a game file which I create using flash cs 5.5. I have another swf file which is hint file which I embedded in that game file. It works fine in pc. I got problems when I tried to load that game file with embedded swf file. I got the following error: SecurityError: Error #3226: Cannot import a SWF file when LoaderContext.allowCodeImport is false. Can anyone tell me why is this happening ?

回答1:

I suppose you're working with adobe air for mobile on your android device. In air for mobile, there is extra restrictions on loading external SWF files - especially when they contain byte codes(ActionScript). Because your secondary SWF file is containing actionscript code for itself, you cannot load into your mobile air application without explicit security allowance.

AS3 uses Loader implicitly when you instantiate classes refering your embedded SWF files, and it loads with default option - which is set to different in air for mobile runtime environment.

You can load them with manual loading, by creating Loader and LoaderContext instance by yourself.

var ldr:Loader = new Loader();
var lc:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain);
lc.allowCodeImport = true;
ldr.load(new URLRequest("YOUR_FILE_PATH"), lc);

Also note that in iOS, even if allowCodeImport is set to true, you cannot load external SWF with codes, by any means.

For further details : http://blogs.adobe.com/airodynamics/2012/11/09/packaging-and-loading-multiple-swfs-in-air-apps-on-ios/



回答2:

Try this kind of Context:

var loaderContext: LoaderContext = new LoaderContext();
loaderContext.allowLoadBytesCodeExecution = true; 
swfLoader.loaderContext = loaderContext;