I have a two files: Main.swf and DataEnter.swf. Each has a Document Class. I try to load DataEnter.swf in Main.swf.
Main.as
package
{
import flash.events.*;
import flash.display.MovieClip;
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.display.Loader;
public class Main extends MovieClip
{
public function Main()
{
var loader: Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, DataEnter_loadComplete);
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onError);
loader.load(new URLRequest('DataEnter.swf'));
}
function DataEnter_loadComplete(evt: Event):void
{
trace(evt.target.content); // DataEnter__Preloader__
var SWF = evt.target.content;
SWF.FooBar(); //Error #1069: Property FooBar not found on DataEnter__Preloader__ and there is no default value
}
}
}
DataEnter.as
package
{
import flash.display.Sprite;
public class DataEnter extends Sprite
{
private var _socketWorker:Foo;
public function setSocketWorker(sw:Foo)
{
_socketWorker = sw;
}
public function FooBar()
{
//do something
}
}
}
When occurs an event Event.COMPLETE of Loader in Main class, the evt.target.content contains object DataEnter_Preloader_.
But it must be “DataEnter“.
What is wrong? How to call method FooBar of Loaded Class ?
I opened DataEnter.swf in FlashDevelopIDE. This shows that my file has two frames, but FlashIDE it has only one frame.
In DocumentClass of DataEnter I have included a class “Foo”, which works with sockets. But, object of this class, passed in constructor.
When I removed the class “Foo” and publish file again, then on loading swf file *DataEnter_Preloader_* is gone, and expected DataEnter was there.
Sorry for Bad English