as3之<a.swf与b.swf数据互访>
import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.display.MovieClip;
var astr:String="a.swf的变量"
var l:Loader=new Loader();
l.load(new URLRequest("b.swf"));
l.contentLoaderInfo.addEventListener(Event.COMPLETE, fun);
function fun(e:Event)
{?? var contents:MovieClip=e.target.content as MovieClip ;
??????? addChild(l);
??????????????? contents.bfun("a.swf调用b.swf的函数")//调用b.swf里面函数;
?????????????? contents.bt.x=0;//bt是b.swf里的一个按钮;
?????????????? contents.bt.addEventListener(MouseEvent.CLICK,afun);
?????????? ? trace(contents.bstr);//bstr是b.swf里的一个变量
}
function afun(e){
gotoAndPlay(2);
trace("b.swf调用a.swf的函数")
}
下面是b.swf里面代码;
import flash.events.MouseEvent;
var bstr:String="b.swf的变量"
//bt.addEventListener(MouseEvent.CLICK,clk);??? //这里可去掉注释,把a.swf里的注释掉,一样的效果
function clk(e:MouseEvent){
var par=MovieClip(parent.parent)
par.afun();
trace(par.astr);
}
function bfun(t:String){
trace(t);
}