/**
 * @(#)SWFDefineButton2Tag.java
 * @author  Intelligent Technology Inc.
 * @version 1.00 2002/4
 */
package	jp.co.iti.swf;

import	java.io.*;
import	jp.co.iti.fagot.util.*;

/**
 * SWF DefineButton TAG(ID=7)を表す。
 */
public class SWFDefineButton2Tag extends SWFTag implements hasSWFActionRecord{
	private	int					myID;
	private	int					myFlags;
	private	int					myOffset;
	private	SWFButtonRecords	myButtonRecords;
	private	int					myActionOffset;
	private	int					myCondition;
	private	SWFActionRecords	myActionRecords;
	
	public	SWFDefineButton2Tag(int id ,byte[] data)
		throws	 SWFButton2TagException ,SWFButtonRecordsException
				,SWFActionRecordsException ,SWFActionRecordException
	{
		super(id ,data);
		myButtonRecords = new SWFButtonRecords();
		myActionRecords = new SWFActionRecords();
		
		SWFInputStream swfstream = new SWFInputStream(new BufferedInputStream(new ByteArrayInputStream(data)));
		try{
			try{
				myID			=	swfstream.readUI16();	// Button ID
				myFlags			=	swfstream.readUI8();	// Flags
				myOffset		=	swfstream.readUI16();	// Offset
				myButtonRecords.readRecords(swfstream, true);		// Buttons
				
				if(0 < myOffset){
					while(true){
						myActionOffset	=	swfstream.readUI16();	// ActionOffset
						myCondition		=	swfstream.readUI16();	// Condition
						myActionRecords.readRecords(swfstream);		// Actions
						if(0 == myActionOffset)	break;
					}
				}

try{
swfstream.readUI8();
ZDebug.trace("DefineButton2 残データあり!?");
}catch(Throwable e){}
			}finally{ swfstream.close(); }
		}catch(IOException e){
			e.printStackTrace();
			throw new SWFButton2TagException();
		}
	}
	
	public	SWFActionRecord[]	getActionRecords(){ return myActionRecords.getActionRecords(); }
}
