2

I have created a lesson book using flash where every unit has many chapters. Their is a combo box to navigate in between the chapter. Those chapters are placed into individual frame. Now, if each chapter is a different .swf file (or HTML flash file if the publish preview is HTML), how can i access them through combo box? here is my code for combo box to navigate in between frame:

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");
}

any help please? thank you!

4

2 回答 2

1

制作一个将加载 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);
}

然后使用 change 事件调用函数

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 语句或其他内容来检查是否需要删除已加载的章节。

于 2012-12-19T10:57:37.910 回答
1

您想要执行以下操作,而不是 gotoAndStop:

ExternalInterface.call('yourJavascriptFunction', combobox.selectedItem.label);

然后,在 Javascript 中,类似:

function yourJavascriptFunction(chapterName) {
  //set source of frame here
}
于 2012-12-19T04:28:24.570 回答