I have a full browser window AS3 Flash CS4 parent swf which loads a third-party child swf, smaller in height/width and positioned appropriately (i.e. centered). No matter what loading technique I try to use, I’m running into placement and orientation problems in the child swf which break the child.
In one example case, the child will load a secondary displayobject (presumably a movieclip), but attempts to attach it to the stage. If I allow it access to the stage via the SecurityDomain during loading, it orients it at 0,0 of the parent swf instead of 0,0 of the child swf (which is already position/centered appropriately).
In another, the child positioning during load is appropriate, but placement inside the child which seem to reference the stage for their X,Y positions is offset by the amount the child swf has been centered (i.e. if the loader of the child swf is centered such that it’s X is at 200, and an object inside the child swf is supposed to be at 100,50, it is actually at 300,50).
The common thread seems to be that the child swfs, whether or not allowed to access the stage, are using stage or player properties of the parent instead of those of their own within the loader.
How can I isolate the child swf such that it only uses it’s own sub-environment for positioning and orientation and not the parent’s?
I have tried the built-in Loader and UILoader, Greensock’s SWFLoader, Flex’s SWFLoader and even loading it via text in a TextField.
It seems like AIR’s HTMLLoader would work (since SWF objects inside the HTMLLoader apparently use their own stage object), but this app has be available in the browser.
Ideally, I’d still like to be able to communicate with the child, but at this point ensuring the child runs successfully is more important.
This seems like a common approach, yet running into blocking issues left and right make me think I’m approaching this in the wrong way.
My last resort is to replace the parent swf with a JS framework, but only if absolutely essential.
Suggestions for solutions at any part of this process would be appreciated.
Hope there’s not an SO “rule” against answering my own question…
As weltraumpirat mentioned in comments, there appears to be no way to restricted a loaded swf from accessing stage variables such as positioning/orientation (mouseX & mouseY). The best solution is to restrict access to the stage so that loaded swfs can not add to it. This is done by including a LoaderContext object with the Loader.load call which defines a separate ApplicationDomain.
This will maintain a separate root in the loaded swf.
In cases where the Loader object has been positioned away from (0,0) in the parent/main swf, You may then need to coordinate with the loaded swf authors to wrap stage.mouseX & stage.mouseY with DisplayObject.globalToLocal to reflect the unknown offset (from within the loaded swf).
It sucks, but it makes sense from a security perspective. I’ve found that it’s just common practice for a Flash developer to not think of the context in which their SWF might be loaded and therefore think nothing wrong with using the stage (instead of the root). Best practice should be to always use the root for adding and position objects because you never know where that root might be placed in the display list and how many parents their might be between it and the stage.