Casting loaderInfo.content (.swf file) to its document class causes compilel err 1180

I have a Flash file (Foo.fla) with a document class Foo that has a movieclip in its library named Bar that is linked to a class Bar (generated bij Flash). The Foo constructor:


public function Foo() {
  addChild(new Bar());
}

Foo.fla compiles to Foo.swf and runs with no errors. Now from a different Flash file (Test.fla) with a document class Test I want to load Foo.swf using the flash.display.Loader class:


var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoad);
loader.load(new URLRequest("Foo.swf"));

In the event handler I get a compile error for Foo.as (the document class for Foo.swf) when I try to cast the content property of the contentLoaderInfo object to an instance of Foo.


private function onLoad(e:Event):void {
  var loaderInfo:LoaderInfo = e.target as LoaderInfo;
  loaderInfo.content as Foo; // Cause a compile error in Foo.as
}

Foo.as, Line 6
1180: Call to a possibly undefined method ProgressBar.
addChild(new Bar());

Foo.as compiles without errors but Test.as causes a compile error in Foo.as which is unexpected.

Why is this happening and what can I do to prevent it?

Thank you!