我有两个swf,A.swf和B.swf:B.swf是A.swf.i的孩子想要访问b.swf中的a.swf变量。这可能吗?我该怎么办?这个? 请用例子说明。 在此先感谢
loader.load(new URLrequest"b.swf"));
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, swfLoaded)
function swfLoaded(e:Event):void
{
data= e.target.content; //data is the String i declared outside
mainContainer.addChild(loader);In this Loader i want to dispaly the data
}
答案 0 :(得分:0)
是的,可能。
var myObj:Object = new Object();
var swfLoader:Loader = new Loader();
var swfFile:URLRequest=new URLRequest("b.swf");
swfLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, swfLoadedHandler);
swfLoader.load(swfFile);
private function swfLoadedHandler(e:Event):void {
myObj = e.target.content;
//trace(myObj.mcBanner.prevImage);
}
现在myObj var包含加载的SWF内容。你可以轻松访问。
答案 1 :(得分:0)
假设这是b.swf中的文档类:
public Class B extends MovieClip {
protected var _theVar:String;
public function get theVar():String {
return _theVar;
}
public function set theVar(value:String):void {
if (value != _theVar) {
_theVar=value;
//do something here with the new value
}
}
public function B () {
super();
}
}
在文档课程中:
//this will be inside a function that detects that the content has been loaded
var bContent = yourLoader.loaderInfo.content as B;
bContent.theVar = 'some value';
答案 2 :(得分:0)
如果您只想将值传递给加载的swf,可以使用参数对象,请参阅 AS3 Pass FlashVars to loaded swf