parent将文本字符串传递给子swf,as3

时间:2010-04-29 08:29:56

标签: flash actionscript-3

父加载Child,并希望将文本字符串传递给Child。 Parent如何传递字符串 给孩子瑞士法郎?

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

'有DynamicTextfield,名为txtBuddy'

1 个答案:

答案 0 :(得分:1)

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"
}