How to hide the unwanted content visible outside of mx:SWFLoader boundaries

February 13th, 2008

The issue:

I was stumbled upon once ago when I loaded my external SWF file authored by the Flash IDE by the help of component and suddenly (?) every content object that was originally placed outside of the Stage inside the Flash IDE became visible in my Flex 2 based web application outside of the boundaries after loading sequence for my external SWF file was over (the file is Flash8 based, AVM1 if this matters).

The corresponding task in Adobe JIRA bug-database:
http://bugs.adobe.com/jira/browse/SDK-14590

I currently fight this issue by applying the mask over the content that is loaded by the component, see the code below, may be you can find it helpful too:

[sourcecode language=”xml”]
<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"
resize="applyMask()" >

<mx:Script>
<![CDATA[
private function applyMask() : void {
if (swf != null &&
swf.content != null &&
swf.content.loaderInfo.width > 0 &&
swf.content.loaderInfo.height > 0) {
var scaleRatioX : Number = swf.content.loaderInfo.width /
this.width;
var scaleRatioY : Number = swf.content.loaderInfo.height /
(this.height – this.controlBar.height);
var scaleRatio : Number = Math.max(scaleRatioX, scaleRatioY);

swf.width = swf.content.loaderInfo.width > 0 ?
Math.round(swf.content.loaderInfo.width / scaleRatio) : 100;
swf.height = swf.content.loaderInfo.height > 0 ?
Math.round(swf.content.loaderInfo.height / scaleRatio) : 100;

var s : Shape = new Shape();
s.graphics.beginFill(0xFFFFFF);
s.graphics.drawRect(0, 0, swf.width, swf.height);
s.graphics.endFill();
swf.addChild(s);
s.visible = false;
swf.mask = s;
}
}
]]>
</mx:Script>
<mx:SWFLoader id="swf"
complete="applyMask()"
source="navigation.swf"/>
</mx:VBox>
[/sourcecode]