Search code examples
actionscript-3apache-flexactionscriptair

"Actionscript Security Sandbox Violation" when click on a symbol inside another symbol


I'm developing an AIR application which loads SWF-files. I add symbols from the loaded SWF-file to a FLEX-canvas:

//...
_loader = new Loader();
var urlReq:URLRequest = new URLRequest(_file);
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, swfLoadCompleted);
_loader.load(urlReq);
//...

private function swfLoadCompleted(loadEvent:Event):void 
{
        var swfApplicationDomain:ApplicationDomain = (loadEvent.target.applicationDomain as ApplicationDomain);
        var symbolNames:Vector.<String> = swfApplicationDomain.getQualifiedDefinitionNames();

        for each (var symbolName:String in symbolNames)
        {
                var clazz:Class = swfApplicationDomain.getDefinition(symbolName) as Class;
                var symbol:Object = new clazz();
                if (symbol is MovieClip)
                {
                    canvas.addChild(symbol);
                }
        }
}

When I click a part of symbol which is symbol placed in another symbol, I get the error:

*** Security Sandbox Violation ***
SecurityDomain 'file:///C:/Users/user1/Desktop/Symbol_in_symbol_example.swf' tried to access incompatible context 'app:/MyProgram.swf'

Because of this error I can't implement drag and drop for this kind of symbols. What can be the cause of this problem?

I attach a SWF-file example


Solution

  • If you want to load classes from one swf file to a air application, you have to load it in two steps.

    1. load the swf file as bytes with an URLLoader
    2. create a normal loader
    3. create a loader context class
    4. set the property allowCodeImport = true
    5. load the data with loadbytes

    EDIT: found this answer AIR Loading server hosted swf into same sandbox