我使用 Flash 创建了一本教科书,其中每个单元都有很多章节。它们是一个组合框,用于在章节之间导航。这些章节被放置在单独的框架中。现在,如果每个章节都是不同的 .swf 文件(如果发布预览是 HTML,则为 HTML flash 文件),我如何通过组合框访问它们?这是我的组合框在框架之间导航的代码:
stop();
combobox.addItem( {label: "Chapter 1" } );
combobox.addItem( {label: "Chapter 2" } );
combobox.addItem( {label: "Chapter 3" } );
combobox.addEventListener(Event.CHANGE, changeFrame);
function changeFrame (event:Event):void{
if (combobox.selectedItem.label == "Chapter 1")
gotoAndStop ("chap1");
else if (combobox.selectedItem.label == "Chapter 2")
gotoAndStop ("chap2");
else if (combobox.selectedItem.label == "Chapter 3")
gotoAndStop ("chap3");
}
请问有什么帮助吗?谢谢!
最佳答案
创建一个函数来加载 swf,并将其显示在屏幕上。
import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.Event;
import flash.display.MovieClip;
function loadSwf(swfURL:String):void
{
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
loader.load(new URLRequest(swfURL);
}
function onComplete(e:Event)
{
var swf:MovieClip = new MovieClip();
swf.addChild(e.currentTarget.content);
addChild(swf);
}
然后使用更改事件调用该函数
function changeFrame (event:Event):void
{
if (combobox.selectedItem.label == "Chapter 1")
loadSwf("chap1.swf");
else if (combobox.selectedItem.label == "Chapter 2")
loadSwf("chap2.swf");
else if (combobox.selectedItem.label == "Chapter 3")
loadSwf("chap3.swf");
}
然后,您需要添加 if 语句或其他内容来检查是否需要删除已加载的章节。
关于actionscript-3 - 如何通过组合框导航到另一个文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13944851/