A have a external SWF file that contains an instance of an object that will be used across multiple projects. It’s accessible as a public property of the external SWF.
When I load the external SWF file using the Loader class everything comes in fine but when I try to assign the value of that property, which traces out as an instance of the correct object, to a local variable the local variable is always null.
Below is a dumbed down sample of what I’m trying to accomplish:
Object Class
package com.derrickcurry
{
import flash.display.Sprite;
public class MyObject extends Sprite
{
public function MyObject():void
{
trace("- MyObject -");
}
public function doWork():void
{
// Does something
}
}
}
External SWF Document Class
package
{
import com.derrickcurry.MyObject;
import flash.display.Sprite;
public class MyExternalMovie extends Sprite
{
public var instance:MyObject;
public function MyExternalMovie():void
{
this.instance = new MyDocument();
}
}
}
SWF Document Class that the loads the External SWF from above
package
{
import flash.display.Sprite;
import com.derrickcurry.MyObject;
public class MyMovie extends Sprite
{
private var myObject:Object;
public function MyMovie():void
{
if (!this.myObject)
{
var url:URLRequest = new URLRequest("http://somedomain.com/MyExternalMovie.swf");
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onMyExternalMovieLoaded);
loader.load(url);
addChild(loader);
}
}
private function onMyExternalMovieLoaded(e:Event):void
{
this.myObject = e.target.content;
trace(this.myObject); // traces [object MyExternalMovie]
trace(this.myObject.instance); // traces [object MyObject]
var localObject:MyObject = this.myObject.instance as MyObject;
trace(localObject); // traces "null"
}
}
}
Is there a reason why I can’t take the value from a property of the externally loaded SWF and assign it to a local variable?