首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何通过单击“下一步”按钮加载swf文件

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

Stack Overflow用户
提问于 2013-01-05 14:10:08
回答 1查看 3.6K关注 0票数 1

我试着用AdobeFlashCS5.5开发课件。我的课件有几节课,每节课都是用.swf文件开发的。我已经添加了 next &前一个按钮来加载next和上一课。但是,只有当我将发布预览设置为HTML时,此功能才能工作。下面是我使用的代码:

代码语言:javascript
复制
function gotoChap1(event:MouseEvent):void {
    navigateToURL(new URLRequest ("chap1.html"),("_self"));
}

chap1_btn.addEventListener(MouseEvent.CLICK , gotoChap1);

现在,当.swf发布预览被设置为闪存时,如何通过单击Next/or按钮来加载(或另一课)文件?我在谷歌上搜索过,但没有运气!谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-01-05 18:45:37

您需要使用Loader而不是navigateToURL函数。您可以创建一个主电影来加载每个外部swf,并在下载完成后添加到主阶段。

使用以下代码实现流程自动化:

代码语言:javascript
复制
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);

在这里下载演示文件:http://cl.ly/Lxj3

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14172555

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档