// Decompiled by DJ v2.6.6.51 Copyright 2000 Atanas Neshkov  Date: 6/15/2001 17:06:12
// Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   com/macromedia/generator/commands/InsertMovieFileCommand

package com.macromedia.generator.commands;

import com.macromedia.generator.api.*;
import com.macromedia.generator.app.*;
import java.util.Properties;

public class InsertMovieFileCommand extends GenericCommand
{

    public InsertMovieFileCommand()
    {
    }

    public void doCommand(FlashEnvironment flashenvironment, Script script, Context context, int i, Properties properties)
        throws FlashCommandException
    {
        _fld0109 = new GenVector(16);
        Script script1 = (Script)_fld0109.add(script.getCommandScript(i));
        String s = properties.getProperty("filename", "");
        String s1 = properties.getProperty("scale", "false");
        String s2 = properties.getProperty("expand", "true");
        String s3 = properties.getProperty("instancename", "");
        String s4 = properties.getProperty("cache", "false");
        s = context.apply(s);
        s1 = context.apply(s1);
        s2 = context.apply(s2);
        s3 = context.apply(s3);
        CacheManager cachemanager = flashenvironment.getCacheManager();
        Object obj = null;
        try
        {
            if(cachemanager != null)
            {
                boolean flag = false;
                if(s4.equalsIgnoreCase("true"))
                    flag = true;
                obj = cachemanager.getMediaData(flashenvironment, s, flag);
            }
            if(obj == null)
                throw new GeneratorApiException("unable to open file");
        }
        catch(GeneratorApiException _ex)
        {
            logError(flashenvironment, "UnableToOpenFile", s);
            _fld0109.release();
            return;
        }
        Script script2;
        try
        {
            script2 = (Script)_fld0109.add(new Script());
            script2.setFileVersion(script.getFileVersion());
            Buffer buffer = new Buffer();
            if(buffer == null)
                throw new GeneratorApiException("buffer is null");
            buffer.write((byte[])obj);
            script2.setBuffer(buffer);
            buffer.release();
            if(cachemanager != null)
                cachemanager.loadExternalFonts(flashenvironment, script2);
            flashenvironment.processScript(script2, context);
        }
        catch(GeneratorApiException _ex)
        {
            logError(flashenvironment, "UnableToOpenFile", s);
            _fld0109.release();
            return;
        }
        try
        {
            int j = script2.getLastFrame();
            int k = script2.getWidth();
            int l = script2.getHeight();
            Matrix matrix = (Matrix)_fld0109.add(new Matrix());
            if(s1.equalsIgnoreCase("true"))
            {
                matrix.setXOffset(-k / 2);
                matrix.setYOffset(-l / 2);
                matrix.setXScale(1.0F / ((float)k / 2048F));
                matrix.setYScale(1.0F / ((float)l / 2048F));
            } else
            {
                matrix.setXOffset(-k / 2);
                matrix.setYOffset(-l / 2);
            }
            script1.mergeScript(script2, 0, 0, 0, j, matrix);
            if(s2.equalsIgnoreCase("true"))
            {
                int i1 = 0;
                int j1 = script1.getLastFrame();
                int k1 = script.getCommandFrameIndex(i);
                int l1 = script.getCommandFrameCount(i);
                if(j1 > l1)
                    i1 = j1 - l1;
                if(i1 > 0)
                    script.insertFrames(k1, i1);
            }
            if(s3 != null)
                script.setCommandLabel(i, s3);
        }
        catch(GeneratorApiException _ex)
        {
            logError(flashenvironment, "UnableToInsertFile", s);
        }
        _fld0109.release();
    }

    GenVector _fld0109;
}