Q:

Loaded Flex SWF overlaps Flash components

I'm working with a Flash project, but need some features of Flex. So I create a Flex application and build it to get the .swf file.
In the Flash project, I use 'Loader' class to load the .swf file created by Flex Builder. This .swf file is loaded and shown on stage well, however, it overlaps all other flash components on stage. The overlapping directions are right-wards and downwards.
The flex mxml file (component.mxml):
<s:Application xmlns:...
width="160" height="120">
...
</s:Application>

Loading to flash using 'Loader' class:
var loader:Loader = new Loader();
loader.load(new URLRequest("component.swf"));
loader.x = COMPONENT_POS_X; //constant
loader.y = COMPONENT_POS_Y; //constant
stage.addChild(loader);

When I try to set width for 'loader', the whole flex component disappears. What's going on?

A:

Solution: Add a mask to the loaded swf.
Source: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Loader.html#methodSummary
When loading a SWF file from an untrusted source (such as a domain other than that of the Loader object's root SWF file), you may want to define a mask for the Loader object, to prevent the loaded content (which is a child of the Loader object) from drawing to portions of the Stage outside of that mask, as shown in the following code:
import flash.display.*;
import flash.net.URLRequest;
var rect:Shape = new Shape();
rect.graphics.beginFill(0xFFFFFF);
rect.graphics.drawRect(0, 0, 100, 100);
rect.graphics.endFill();
addChild(rect);
var ldr:Loader = new Loader();
ldr.mask = rect;
var url:String = "http://www.unknown.example.com/content.swf";
var urlReq:URLRequest = new URLRequest(url);
ldr.load(urlReq);
addChild(ldr);

