Actionscript 3 如何通过单击“下一步”按钮加载swf文件

Actionscript 3 如何通过单击“下一步”按钮加载swf文件,actionscript-3,button,flash,Actionscript 3,Button,Flash,我试着用AdobeFlashCS5.5开发课件。我的课件有几节课,每节课都是在单独的flash(.swf)文件中开发的。我添加了Next和Previous按钮来加载下一课和上一课。但是,只有当我将发布预览设置为HTML时,此功能才起作用。以下是我使用的代码: function gotoChap1(event:MouseEvent):void { navigateToURL(new URLRequest ("chap1.html"),("_self")); } chap1_btn.add

我试着用AdobeFlashCS5.5开发课件。我的课件有几节课,每节课都是在单独的flash(
.swf
)文件中开发的。我添加了NextPrevious按钮来加载下一课和上一课。但是,只有当我将发布预览设置为HTML时,此功能才起作用。以下是我使用的代码:

function gotoChap1(event:MouseEvent):void {
    navigateToURL(new URLRequest ("chap1.html"),("_self"));
}

chap1_btn.addEventListener(MouseEvent.CLICK , gotoChap1);

现在,当发布预览设置为Flash时,如何通过单击下一步/上一步按钮加载.swf(或其他课程)文件?我在谷歌上搜索了一下,但是运气不好!谢谢大家!

您需要使用加载程序,而不是导航URL功能。您可以创建一个主电影来加载每个外部swf,并在下载完成后添加到主阶段

使用以下代码自动执行此过程:

import flash.display.Loader;
import flash.events.Event;
import flash.events.MouseEvent;

// Vars
var currentMovieIndex:uint = 0;
var currentMovie:Loader;
// Put your movies here
var swfList:Array = ["swf1.swf", "swf2.swf", "swf3.swf"];

// Add the event listener to the next and previous button
previousButton.addEventListener(MouseEvent.CLICK, loadPrevious);
nextButton.addEventListener(MouseEvent.CLICK, loadNext);


// Loads a swf at secified index
function loadMovieAtIndex (index:uint) {

    // Unloads the current movie if exist
    if (currentMovie) {
        removeChild(currentMovie);
        currentMovie.unloadAndStop();
    }

    // Updates the index
    currentMovieIndex = index;

    // Creates the new loader
    var loader:Loader = new Loader();
    // Loads the external swf file
    loader.load(new URLRequest(swfList[currentMovieIndex]));

    // Save he movie reference 
    currentMovie = loader;

    // Add on the stage
    addChild(currentMovie);
}

// Handles the previous button click
function loadPrevious (event:MouseEvent) {
    if (currentMovieIndex) { // Fix the limit
        currentMovieIndex--; // Decrement by 1
        loadMovieAtIndex(currentMovieIndex);
    }
}

// Handles the next button click
function loadNext (event:MouseEvent) {
    if (currentMovieIndex < swfList.length-1) { // Fix the limit
        currentMovieIndex++; // Increment by 1
        loadMovieAtIndex(currentMovieIndex);
    }
}

// Load the movie at index 0 by default
loadMovieAtIndex(currentMovieIndex);
导入flash.display.Loader;
导入flash.events.Event;
导入flash.events.MouseEvent;
//瓦尔斯
var currentMovieIndex:uint=0;
变量:加载程序;
//把你的电影放在这里
var swfList:Array=[“swf1.swf”、“swf2.swf”、“swf3.swf”];
//将事件侦听器添加到“下一步”和“上一步”按钮
previousButton.addEventListener(MouseEvent.CLICK,loadPrevious);
addEventListener(MouseEvent.CLICK,loadNext);
//在安全索引处加载swf
函数加载电影索引(索引:uint){
//卸载当前电影(如果存在)
如果(当前电影){
removeChild(当前电影);
currentMovie.unloadAndStop();
}
//更新索引
currentMovieIndex=索引;
//创建新的加载程序
变量加载器:加载器=新加载器();
//加载外部swf文件
load(新的URLRequest(swfList[currentMovieIndex]);
//保存电影参考资料
currentMovie=加载器;
//上台
addChild(当前电影);
}
//处理上一个按钮的单击
函数loadPrevious(事件:MouseEvent){
如果(currentMovieIndex){//修复限制
currentMovieIndex--;//递减1
loadMovieAtIndex(当前电影索引);
}
}
//处理单击“下一步”按钮
函数loadNext(事件:MouseEvent){
如果(currentMovieIndex
在此处加载演示文件: