目录
1、想知道:Flash子swf调用父swf中的方法+父swf加载卸载子swf+父物体回调子swf方法等
1、注意:Flash文件父子物体必须不能是中文,否则就无法加载里面的方法,只能打开它
三、操作:一:子swf调用父swf中的方法(子swf给父swf发送消息)
一、目的
1、想知道:Flash子swf调用父swf中的方法+父swf加载卸载子swf+父物体回调子swf方法等
二、参考
三、注意:
1、注意:Flash文件父子物体必须不能是中文,否则就无法加载里面的方法,只能打开它
三、操作:一:子swf调用父swf中的方法(子swf给父swf发送消息)
1、子物体写上这个(给父物体发送函数消息)“HIDE”是主swf里面的函数
dispatchEvent(new Event("Remove_dongHua"));
三、操作:二:父swf加载卸载子swf
1、父物体写上这个,调用的是同路径下的swf,这样就打开了子swf了,变量是全局的,
//加载子swf,全局变量,并且将其初始化为空
var swfRequest:URLRequest = null;
var loader:Loader = null;
var loaderSwf:Loader = null;
2、在需要的地方播放子swf(不为空的时候才能创建)
if(swfRequest ==null)
{
swfRequest = new URLRequest("动画.swf");
loader = new Loader();
loader.load(swfRequest);
//监听子物体发来消息;
if (! loader.contentLoaderInfo.hasEventListener(Event.COMPLETE))
{
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
}
stage.addChild(loader);
}
3、父swf接受子swf发送来的消息,将子swf删除掉(注意:参考固始国防知识竞答那样子删除子swf否则删除不干净)(对应每一个你创建的物体将其该删除的删除然后将其为空)(最好不删除而是使用隐藏,直接是loader.visible=false就可以了)
为空时候才创建
function completeHandler(e : Event)
{
if(loaderSwf ==null)
{
loaderSwf = Loader(e.target.loader);
if (! loaderSwf.content.hasEventListener("Remove_dongHua"))
{
loaderSwf.content.addEventListener("Remove_dongHua", Remove_dongHua);
}
}
}
function Remove_dongHua(e : Event)
{
Remove_dongHua_current
}
function Remove_dongHua_current()
{
if (swfRequest!=null)
{
swfRequest = null;
}
if (loaderSwf!=null)
{
if (loaderSwf.content.hasEventListener("Remove_dongHua"))
{
loaderSwf.content.removeEventListener("Remove_dongHua", Remove_dongHua);
}
loaderSwf = null;
}
if (loader!=null)
{
if (loader.contentLoaderInfo.hasEventListener(Event.COMPLETE))
{
loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, completeHandler);
}
if (stage.contains(loader))
{
stage.removeChild(loader);
}
loader.unloadAndStop();
loader = null;
}
}
三、操作:三:父物体回调子swf方法等
1、父swf中建立一个全局变量,
var demo:MovieClip;
2、依照前文再父swf中加载了子swf后,子swf里面将自己变为一个MovieClip,再赋值给demo,这样直接就是在父swf中操作demo就是操作子swf了(我在这里是直接对子swf中的Text操作的,函数的话直接
demo.StartDjs();
就可以了)(如果需要将父swf里面demo传递给子swf中,只需要传递一个参数给子swf,参数就是demo,子swf中有一个函数SetParent(e:MovieClip))