views:

96

answers:

1

Parent loads Child, and wants to pass text string to Child. How can Parent pass a string to Child swf?

PARENT.SWF

//LOAD CHILD 'has a symbol on stage called LDR that CHILD loads into'
var loadCHILD:Loader = new Loader();
LDR.addChild(loadCHILD);
var bgURLTxt:URLRequest = new URLRequest("CHILD.swf");
loadCHILD.load(bgURLTxt);
//ATTEMPT TO COMMUNICATE WITH CHILD TXT
function handler(event:Event):void {
LDR = (event.target.loader.content as MovieClip);
var textBuddy:MovieClip = event.target.content.root.txtBuddy;
//MY TEXT
var txtTest:String;
txtTest = "my bad";
trace(txtTest);
}

CHILD.SWF

'has DynamicTextfield called txtBuddy'

+2  A: 
var loader:Loader = new Loader();
LDR.addChild(loader);
var bgURLTxt:URLRequest = new URLRequest("CHILD.swf");
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadHandler);
loader.load(bgURLTxt);

private function loadHandler(event:Event):void 
{
  var child:MovieClip = MovieClip(event.target.content);
  //assuming txtBuddy is the instance name of the text field
  var textBuddy:TextField = child.txtBuddy; 
  textBuddy.text = "This is a text from parent to a text field on child"
}
Amarghosh
Thanks, that worked perfectly once I removed 'private'
VideoDnd