title: How to run an external SWF inside a Flex Application?
body: <p><strong>EDIT: Due to the answer I change the code posted. I've added the</strong> <code>Security.allowDomain("*")</code> <strong>line and that line throws me an error. So, how can that be made?</strong></p>
  
  <p>I want to run an Action Script 3.0 Application into a Flex Application. To do this I've done the following:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;mx:WindowedApplication windowComplete="loadSwfApplication()" xmlns:mx="http://www.adobe.com/2006/mxml"&gt;
  
      &lt;mx:Script&gt;
          &lt;![CDATA[
              private function loadSwfApplication()
              {
                  // The next line throws me an error.
                  Security.allowDomain("*");
  
                  var urlRequest:URLRequest = new URLRequest("path/to/the/application.swf");
                  swfLoader.addEventListener(Event.COMPLETE, loadComplete);
                  swfLoader.load(urlRequest);
              }
  
              private function loadComplete(completeEvent:Event)
              {
                  var swfApplication:* = completeEvent.target.content;
                  swfApplication.init();  // this is a Function that I made it in the Root class of swfApplication
              }
          ]]&gt;
      &lt;/mx:Script&gt;
  
      &lt;mx:SWFLoader id="sfwLoader"/&gt;
  
  &lt;/mx:WindowedApplication&gt;
  </code></pre>
  
  <p>The problem is that in the calling of <code>swfApplication.init();</code> the AIR Player throws me an exception:</p>
  
  <p><strong>Security sandbox violation: caller file:///path/to/the/application.swf cannot access Stage owned by app:/SWFApplicationLoader.swf.</strong></p>
  
  <p>This is because somewhere in <code>application.swf</code> I use the stage like this:</p>
  
  <pre><code>if (root.stage != null)
      root.stage.addEventListener(Event.REMOVED, someFunction);
  root.stage.stageFocusRect = false;
  </code></pre>
  
  <p>How can I load this swf application and USE the stage without any problems?</p>