1

Adobe Flash CS5.5 を使用してコースウェアを開発しようとしていました。私のコースウェアにはいくつかのレッスンがあり、各レッスンは個別のフラッシュ ( .swf) ファイルで作成されます。次と前のレッスンをロードするための [次へ] ボタンと[へ] ボタンを追加しました。ただし、これはPublish PreviewHTMLに設定した場合にのみ機能します。これが私が使用したコードです:

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

chap1_btn.addEventListener(MouseEvent.CLICK , gotoChap1);

パブリッシュ プレビューがFlashに設定されている場合、[次へ/前へ] ボタンをクリックして .swf (または別のレッスン) ファイルを読み込むにはどうすればよいですか? 私はそれをグーグルで検索しましたが、運がありません!ありがとう!

4

1 に答える 1

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

于 2013-01-05T18:45:37.910 に答える