How to load swf file by clicking Next button

前端 未结 1 929
忘了有多久
忘了有多久 2021-01-25 10:04

I was trying to develop courseware using Adobe Flash CS5.5. My courseware has several lesson and each lesson developed in individual flash (.swf) file. I\'ve added

1条回答
  •  北海茫月
    2021-01-25 10:15

    You need to use a Loader instead of the navigateToURL function. You can create a Main movie to load each external swf and add in the main stage when the download complete.

    Use the following code to automate the process:

    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);
    

    Dowload the demo files here: http://cl.ly/Lxj3

    0 讨论(0)
提交回复
热议问题