/*
 *  ChangeVisibility.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 how to change the transparency of a shape:
 *
 * To run this example, type the following on a command line:
 *
 *     java -cp cookbook.jar ChangeVisibility 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.
*/
public class ChangeVisibility
{
    public static void main(String[] args)
    {
        try
        {
            String out = args.length == 0 ? "ChangeVisibility.swf" : args[0];
            ChangeVisibility example = new ChangeVisibility();         
            FSMovie movie = new FSMovie();            
            example.createMovie(movie);
            movie.encodeToFile(out);
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
    
    void createMovie(FSMovie movie)
    {
        int xLower = 0;
        int yLower = 0;
        int xUpper = 8000;
        int yUpper = 8000;
        
        float framesPerSecond = 12.0f;

        movie.setFrameRate(framesPerSecond);
        movie.setFrameSize(new FSBounds(xLower, yLower, xUpper, yUpper));
        movie.add(new FSSetBackgroundColor(FSColorTable.lightblue()));
        
        FSDefineShape rectangle = createRectangle(movie);
        movie.add(rectangle);

        movie.add(new FSPlaceObject2(rectangle.getIdentifier(), 1, 4000, 4000));
        movie.add(new FSShowFrame());
        
        int delta = 0;
        int step = 10;
        int count = 255/step; 
        
        /* Decrease the alpha so the object fades from view */
        
        for (int i=0; i