从外部 swf 中的按钮加载外部 swf 并卸载自身?

发布于 2024-09-02 02:07:49 字数 258 浏览 3 评论 0原文

我是闪存 AS3 的超级新手。我无意听起来像个白痴,但说实话,我花了很长时间才弄清楚如何加载外部 .swf 到我的主文件中!现在我的朋友问我是否可以在外部 .swf 中添加一个按钮,该按钮将自行卸载并在其位置加载新的按钮...
我已经在论坛中寻找答案有一段时间了,我相信现在是我崩溃、承认失败并寻求帮助的时候了。
有人可以告诉我这并不那么困难吗..?当然有可能......
预先感谢您提供任何建议!我期待可以在这里发表回复!

I am an uber n00b to flash AS3. And it is not my intention to sound like a complete moron, but honestly, I have had a hard enough time figuring out just how to load an external .swf into my main file! And now my friend is asking me if I could please add a button within the external .swf which will unload itself and load a new on in its place...
I have looked around in the forums for an answer for a while now and I believe it is time for me to break down, admit defeat, and ask for help.
Can someone please tell me it's not that difficult..? Surely it is possible...
Thank you in advance for any advice at all! I am looking forward to the time when I can post a response here!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

音盲 2024-09-09 02:07:49

我有解决办法!而这才过去了24小时。我统治!
我遇到了 dispatchEvent 并解决了它!

...如果将来有人看到此页面来寻求这个看似不可能完成的任务的答案,那么他们现在就会得到答案!如果我在引用我所做的事情时没有正确的术语,请原谅我。开始了...

在我的外部 .swf 中,我需要为我的按钮(位于我的外部 swf 中)设置一个侦听器事件。然后在我的按钮的函数中包含一个dispatchEvent。我在参数中加入了“true”,以将事件“冒泡”回主时间线。他是我的一个按钮的例子。

mc_main_menu.btn_entertainment.addEventListener(MouseEvent.CLICK, button4);
function button4(event:MouseEvent) {  
dispatchEvent(new Event("btn4", true));  
}

好的,但这只是实现这一目标的一半代码。所以现在,在我加载外部 swf 的主 swf 中,我需要做几件事:
1)。从内存中卸载当前的 swf,以便它停止播放声音
2)。在我的外部 swf 中为dispatchEvent 设置一个侦听器(它将冒泡)
3)。加载新的外部 swf

loader.addEventListener("btn4", page4Swf)
function page4Swf(event:Event):void{<p>
Loader(event.currentTarget).unloadAndStop();  //completely removes the swf from memory  
var SWFRequest:URLRequest = new URLRequest("page4.swf");  
loader.x = Xpos;  
loader.y = Ypos;  //these are to offset the loaded swf, if you wish  
addChild(loader);  
}

就是这样!老实说,我没想到我会这么快在这里发布回复!

I have the solution! And it's only been 24 hours. I rule!
I came across dispatchEvent and that solved it!

...In case someone comes across this page seeking the answer to this seemingly-impossible-task-for-a-n00bie in the future, then they will have the answer right now! Please forgive me if I don't have the correct terminology in referencing what I did. Here we go...

In my external .swf I needed to set a listener event to my buttons (which are in my external swf). Then include a dispatchEvent within the function for my buttons . I included "true" in the arguments to 'bubble' the event back up to the main timeline. He's an example of one of my buttons.

mc_main_menu.btn_entertainment.addEventListener(MouseEvent.CLICK, button4);
function button4(event:MouseEvent) {  
dispatchEvent(new Event("btn4", true));  
}

Ok, but that's only half of the code to make it happen. So now, in my main swf, in which I load the external swfs into, I needed to do several things:
1). Unload the current swf from memory so that it will stop playing sounds
2). Set a listener for the dispatchEvent in my external swf (which will bubble up)
3). Load the new external swf

loader.addEventListener("btn4", page4Swf)
function page4Swf(event:Event):void{<p>
Loader(event.currentTarget).unloadAndStop();  //completely removes the swf from memory  
var SWFRequest:URLRequest = new URLRequest("page4.swf");  
loader.x = Xpos;  
loader.y = Ypos;  //these are to offset the loaded swf, if you wish  
addChild(loader);  
}

And there it is! I honestly didn't think that I'd be posting a response on here THAT quickly!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文