Mag Roader
Mag Roader

Reputation: 7170

AS3 Error 1014 when loading multiple local SWFs

I have two SWFs, call them A and B. They will never be deployed to a website, and are being used for tools. B depends on A - some of the classes in B extend classes in A.

I am now creating a 3rd SWF, call it X. X is attempting to load A and B using a flash.display.Loader and flash.net.URLRequest. A and B paths are pushed into an array, and then called in a loadLibrary function like so:

public class LibraryLoader
{
    private static const CLASS_NAME:String = "LibraryLoader";
    private var _libraries:DisplayObjectContainer;

    ...

    public function loadLibrary(callback:Function, libName:String):void
    {
        trace("loadLibrary('" + libName + "')");

        var loader:Loader = new Loader();
        loader.name = libName;

        var listener:Function = function(e:Event):void
        {
            trace("finished loading '" + libName + "', event: " + e);
            loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, listener);
            _libraries.addChild(loader);
            callback();
        }

        loader.contentLoaderInfo.addEventListener(Event.COMPLETE, listener);
        loader.load(new URLRequest(libName));
    }

Problem is, when I load B, it throws an error. Here's the output:

loadLibrary('C:\path\to\A.swf')
finished loading 'C:\path\to\A.swf', event: [Event type="complete" bubbles=false cancelable=false eventPhase=2]
loadLibrary('C:\path\to\B.swf')
[Fault] exception, information=VerifyError: Error #1014: Class a.class.in::A could not be found.

This class is inside A, and B depends on it.

I Googled around and found information about Security permissions and sandboxes - perhaps I need to set up some trust between these SWFs. That's fine, but I can't seem to figure out how to do it properly.

For one, I tried setting up a LoaderContext like so (when loading both SWFs):

var context:LoaderContext = new LoaderContext();
context.applicationDomain=ApplicationDomain.currentDomain;
loader.load(new URLRequest(libName), context);

No dice, there; same error. In addition, attempting to set context.securityDomain throws out:

[Fault] exception, information=SecurityError: Error #2142: Security sandbox violation: local SWF files cannot use the LoaderContext.securityDomain property. file:///C|/path/to/X.swf was attempting to load file:///C:/path/to/A.swf.

In case it makes a difference, A and B are being compiled using compc.exe from the Flex SDK (3.6). I generate both a SWF and a SWC for each - SWFs for runtime, and SWCs for compiling - using compc. Here is the command line for compc:

compc.exe  -output C:\temp\dir -source-path   -include-sources C:\path\to\A\source -directory=true -incremental=true -debug=true  -use-network=false 
compc.exe  -output C:\path\to\A.swc -source-path   -include-sources C:\path\to\A\source -incremental=true -debug=true  -use-network=false 
compc.exe  -output C:\temp\dir -source-path   -include-sources C:\path\to\B\source -directory=true -incremental=true -debug=true  -external-library-path+=C:\path\to\A.swc -use-network=false 

After the first and 3rd compilations, a "library.swf" file is dropped into the temporary directory listed. I take those SWFs out and rename them to A.swf and B.swf, dropping them where I want them.

My project for X is built in FlashDevelop 4.0.1 for Flash Player 10.1.

I know that a.class.in::A is included in SWF A. I am loading these SWFs in a Scaleform runtime with no issues, and am therefore convinced there is some kind of issue with how FlashPlayer is doing things.

How can I get B to see the classes inside A when I load A and B from X?

Upvotes: 1

Views: 453

Answers (1)

fsbmain
fsbmain

Reputation: 5267

There are three comments:

  1. You were right, when you specified the applicationDomain to ApplicationDomain.currentDomain; without this loader loads swf to separate child domains with common parent, so they don't see classes of each other.
  2. With common application domain, classes from A must be accessible from B, so I see only one possibility for the error: A really hasn't class some.class.in.A. Try to check is this class is included to A (for example by Sothink SWF Decompiler) or simply check if this class is used explicitly in the code in A. if it isn't used it not be included, nut you can force to include this class by adding it in the code: simply add some.class.in.A some where in the A without new statement.
  3. context.securityDomain is for other purposes, it is used only when swf files loaded by http, and don't applies locally.

Upvotes: 1

Related Questions