2013-01-05 87 views
1

我試圖使用Adobe Flash CS5.5開發課件。我的課件有幾個課程,每個課程在單獨的閃存(.swf)文件中開發。我已添加下一個 & 上一個按鈕用於加載下一課和上一課。但是,這個東西只有當我設置發佈預覽HTML。這裏是代碼我使用:如何通過單擊下一步按鈕加載swf文件

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

chap1_btn.addEventListener(MouseEvent.CLICK , gotoChap1); 

現在,我怎麼可以加載瑞士法郎(或其他課程)的文件,單擊Next /上一頁按鈕時發佈預覽設置爲閃存?我GOOGLE了它,但沒有運氣!謝謝!

回答

2

您需要使用加載程序而不是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

相關問題