/*
 *  BasicLevels.java
 *  Cookbook
 *
 *  Copyright (c) 2001-2009 Flagstone Software Ltd. All rights reserved.
 *
 *  This code is distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
 *  EXPRESS OR IMPLIED, AND Flagstone HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING
 *  WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 *  PURPOSE, AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
 */

import com.flagstone.transform.*;

import java.util.*;

/*
 * This example shows some of the basic concepts used when loading movie clips
 * onto different levels in a movie.
 *
 * To run this example, type the following on a command line:
 *
 *     java -cp cookbook.jar BasicLevels file-out
 *
 * where
 *
 *     file-out is the path where the file will be written. If no output file 
 *     is specified then a file named after the example will be written to the 
 *     current directory.
 *     
 * NOTE: This example uses movies included in the Cookbook release to make it
 * easier to set different targets where the movie clips should be loaded. The 
 * paths are hardwired to keep the code simple so make sure you are in the root 
 * directory of the cookbook code before running the example.
 */
public class BasicLevels
{
    public static void main(String[] args)
    {      
        try
        {
               String out = args.length == 0 ? "BasicLevels.swf" : args[0];
            BasicLevels example = new BasicLevels(); 
            
            // Load an existing movie and add the actions to load
            // the movie clips.
            FSMovie movie = new FSMovie("files/BasicLevels.swf");
            
            example.createMovie(movie);
            movie.encodeToFile(out);
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }

    public void createMovie(FSMovie movie)
    {
        // The following code loads two pre-defined movie clips into the 
        // main movie. You can also set the target to be a web page or
        // frame.
        
        FSDoAction load1 = new FSDoAction(new ArrayList());
        
        // Movie clips can be loaded with the FSGetUrl action with the 
        // URL to load and the target level specified in the action
        
        load1.add(new FSGetUrl("files/BasicLevels1.swf", "_level1"));

        movie.add(load1);
        movie.add(FSShowFrame.getInstance());
        
        // Allow sufficient time for the movie clip to play.
        
        for (int i=0; i<5; i++) {
            movie.add(FSShowFrame.getInstance());
        }
        
        FSDoAction load0 = new FSDoAction(new ArrayList());
        
        // FSGetUrl2 is more flexible than FSGetUrl as it uses values for the 
        // URL and target from the Flash Player's stack. In addition to loading 
        // files you can also post variable values to a server at the same time. 
        // See the class documentation for more information.
        
        load0.add(new FSPush("files/BasicLevels2.swf"));
        load0.add(new FSPush("_level0"));
        load0.add(new FSGetUrl2(FSGetUrl2.MovieToTarget));

        movie.add(load0);
        movie.add(FSShowFrame.getInstance());
    }
}