【问题标题】:How to load swf file by clicking Next button如何通过单击下一步按钮加载 swf 文件
【发布时间】:2013-01-05 14:10:08
【问题描述】:

我尝试使用 Adob​​e Flash CS5.5 开发课件。我的课件有几节课,每节课都是在单独的 flash (.swf) 文件中开发的。我添加了 NextPrevious 按钮来加载下一课和上一课。但是,这个东西只有在我将 Publish Preview 设置为 HTML 时才有效。这是我使用的代码:

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

chap1_btn.addEventListener(MouseEvent.CLICK , gotoChap1);

现在,当 Publish Preview 设置为 Flash 时,如何通过单击 Next/Previous 按钮来加载 .swf(或其他课程)文件?我用谷歌搜索了它,但没有运气!谢谢!

【问题讨论】:

    标签: actionscript-3 button flash


    【解决方案1】:

    您需要使用 Loader 而不是 navigateToURL 函数。您可以创建一个主电影来加载每个外部 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);
    

    在此处下载演示文件:http://cl.ly/Lxj3

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-13
      相关资源
      最近更新 更多