// Decompiled by DJ v2.6.6.51 Copyright 2000 Atanas Neshkov  Date: 6/15/2001 17:06:14
// 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/InsertSoundCommand

package com.macromedia.generator.commands;

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

public class InsertSoundCommand extends GenericCommand
{

    public InsertSoundCommand()
    {
    }

    public void doCommand(FlashEnvironment flashenvironment, Script script, Context context, int i, Properties properties)
        throws FlashCommandException
    {
        int j = 1;
        String s = properties.getProperty("name", "");
        String s1 = properties.getProperty("loop", "1");
        s = context.apply(s);
        s1 = context.apply(s1);
        String s2 = properties.getProperty("instancename", "");
        s2 = context.apply(s2);
        try
        {
            if(s2 != null)
                script.setCommandLabel(i, s2);
        }
        catch(GeneratorApiException _ex)
        {
            logError(flashenvironment, "UnableToSetInstanceName", s2);
        }
        if(s == null)
        {
            logError(flashenvironment, "MissingSoundName", null);
            return;
        }
        try
        {
            j = Integer.valueOf(s1).intValue();
            if(j < 1 || j > 1000)
            {
                logError(flashenvironment, "InvalidLoopRange", s1);
                j = 1;
            }
        }
        catch(NumberFormatException _ex)
        {
            logError(flashenvironment, "InvalidLoopValue", s1);
            j = 1;
        }
        Sound sound = script.findSound(s);
        if(sound == null)
            sound = flashenvironment.getTemplate().findSound(s);
        if(sound != null)
        {
            try
            {
                int k = script.getCommandFrameIndex(i);
                script.insertSound(sound, k, j);
            }
            catch(GeneratorApiException _ex)
            {
                logError(flashenvironment, "UnableToInsertSound", s);
                return;
            }
            sound.release();
        } else
        {
            logError(flashenvironment, "UnableToFindSound", s);
        }
    }
}