Hello,
I have a swf which load an external swf. The loader swf has a variable which i want to access from the loaded swf. I use MovieClip(parent.parent).myVar
but it return this error
TypeError: Error #1009: Cannot access a property or method of a null object reference. at card01_fla::MainTimeline/frame1()
The loader swf has a custom Document Class which i think is the problem.
Thanks in advance.
EDIT
This is the as of the main swf
package
{
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.net.URLRequest;
import flash.text.TextField;
/**
* ...
* @author chchrist
*/
public class CardSender extends Sprite
{
private var loader:Loader;
private var viewButtonArray:Array;
private var sendButtonArray:Array;
private var cardContainer:Sprite;
public var testVar:String
public function CardSender() {
testVar = "it worked!!!";
init();
}
private function init() {
viewButtonArray = [cardsenderMC.view01, cardsenderMC.view02, cardsenderMC.view03, cardsenderMC.view04];
for each( var viewButton in viewButtonArray) {
viewButton.buttonMode = true;
viewButton.addEventListener(MouseEvent.CLICK, onViewClick);
}
}
private function onViewClick(e:MouseEvent):void {
var cardName = "card"+e.target.name.substring(4)+".swf";
loader = new Loader();
loader.load( new URLRequest(cardName));
loader.contentLoaderInfo.addEventListener(Event.INIT, onCardInit);
}
private function onCardInit(e:Event):void {
addChild(loader);
var content:* = loader.content;
content.closeButton.addEventListener(MouseEvent.CLICK, onCloseClick);
}
private function onCloseClick(e:MouseEvent):void {
removeChild(loader);
}
}
}
and I am trying to access the test variable from the loaded swf with this code
trace(MovieClip(parent.parent).testVar);
EDIT#2
If I addChild(loader)
not in the onCardInit but in the onViewClick and in the first frame of the loaded swf i have Object(parent.parent).testVar
it works...but why it doesn't want to be inside the onCardInit function?