?? actionparser.java
字號:
/****************************************************************
* Copyright (c) 2001, David N. Main, All rights reserved.
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the
* following conditions are met:
*
* 1. Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer.
*
* 2. Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name of the author may not be used to endorse or
* promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
****************************************************************/
package com.anotherbigidea.flash.readers;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Stack;
import java.util.Vector;
import com.anotherbigidea.flash.SWFActionCodes;
import com.anotherbigidea.flash.SWFConstants;
import com.anotherbigidea.flash.interfaces.SWFActions;
import com.anotherbigidea.io.InStream;
/**
* Parse action bytes and drive a SWFActions interface
*/
public class ActionParser implements SWFActionCodes
{
protected SWFActions actions;
protected int blockDepth = 0;
protected String mStringEncoding = SWFConstants.STRING_ENCODING_MX;
public ActionParser( SWFActions actions, int flashVersion )
{
this.actions = actions;
if( flashVersion < SWFConstants.FLASH_MX_VERSION ) {
mStringEncoding = SWFConstants.STRING_ENCODING_PRE_MX;
}
}
public synchronized void parse( byte[] bytes ) throws IOException
{
Vector records = createRecords( bytes );
processRecords( records );
}
public synchronized void parse( InStream in ) throws IOException
{
Vector records = createRecords( in );
processRecords( records );
}
protected void processRecords( Vector records ) throws IOException
{
//--process action records
for( Enumeration enum = records.elements(); enum.hasMoreElements(); )
{
ActionRecord rec = (ActionRecord)enum.nextElement();
//actions.comment( "depth=" + rec.blockDepth );
//detect end of block
if( rec.blockDepth < blockDepth )
{
blockDepth--;
actions.endBlock();
}
if( rec.label != null ) actions.jumpLabel( rec.label );
int code = rec.code;
byte[] data = rec.data;
InStream in = (data!=null && data.length > 0) ? new InStream(data) : null;
switch( code )
{
case 0: actions.end(); break;
//--Flash 3
case GOTO_FRAME : actions.gotoFrame( in.readUI16() ); break;
case GET_URL : actions.getURL( in.readString(mStringEncoding), in.readString(mStringEncoding) ); break;
case NEXT_FRAME : actions.nextFrame(); break;
case PREVIOUS_FRAME: actions.prevFrame(); break;
case PLAY : actions.play(); break;
case STOP : actions.stop(); break;
case TOGGLE_QUALITY: actions.toggleQuality(); break;
case STOP_SOUNDS : actions.stopSounds(); break;
case WAIT_FOR_FRAME: actions.waitForFrame( in.readUI16(), rec.jumpLabel ); break;
case SET_TARGET : actions.setTarget( in.readString(mStringEncoding) ); break;
case GOTO_LABEL : actions.gotoFrame( in.readString(mStringEncoding) ); break;
//--Flash 4
case IF : actions.ifJump( rec.jumpLabel ); break;
case JUMP : actions.jump( rec.jumpLabel ); break;
case WAIT_FOR_FRAME_2: actions.waitForFrame( rec.jumpLabel ); break;
case POP : actions.pop(); break;
case PUSH : parsePush( data.length, in ); break;
case ADD : actions.add(); break;
case SUBTRACT : actions.substract(); break;
case MULTIPLY : actions.multiply(); break;
case DIVIDE : actions.divide(); break;
case EQUALS : actions.equals(); break;
case LESS : actions.lessThan(); break;
case AND : actions.and(); break;
case OR : actions.or(); break;
case NOT : actions.not(); break;
case STRING_EQUALS : actions.stringEquals(); break;
case STRING_LENGTH : actions.stringLength(); break;
case STRING_ADD : actions.concat(); break;
case STRING_EXTRACT : actions.substring(); break;
case STRING_LESS : actions.stringLessThan(); break;
case MB_STRING_EXTRACT : actions.substringMB(); break;
case MB_STRING_LENGTH : actions.stringLengthMB(); break;
case TO_INTEGER : actions.toInteger(); break;
case CHAR_TO_ASCII : actions.charToAscii(); break;
case ASCII_TO_CHAR : actions.asciiToChar(); break;
case MB_CHAR_TO_ASCII : actions.charMBToAscii(); break;
case MB_ASCII_TO_CHAR : actions.asciiToCharMB(); break;
case CALL : actions.call(); break;
case GET_VARIABLE : actions.getVariable(); break;
case SET_VARIABLE : actions.setVariable(); break;
case GET_URL_2 : parseGetURL2( in.readUI8() ); break;
case GOTO_FRAME_2 : actions.gotoFrame( in.readUI8() != 0 ); break;
case SET_TARGET_2 : actions.setTarget(); break;
case GET_PROPERTY : actions.getProperty(); break;
case SET_PROPERTY : actions.setProperty(); break;
case CLONE_SPRITE : actions.cloneSprite(); break;
case REMOVE_SPRITE : actions.removeSprite(); break;
case START_DRAG : actions.startDrag(); break;
case END_DRAG : actions.endDrag(); break;
case TRACE : actions.trace(); break;
case GET_TIME : actions.getTime(); break;
case RANDOM_NUMBER : actions.randomNumber(); break;
//--Flash 5
case INIT_ARRAY : actions.initArray(); break;
case LOOKUP_TABLE : parseLookupTable( in ); break;
case CALL_FUNCTION : actions.callFunction(); break;
case CALL_METHOD : actions.callMethod(); break;
case DEFINE_FUNCTION : parseDefineFunction(in); break;
case DEFINE_LOCAL_VAL : actions.defineLocalValue(); break;
case DEFINE_LOCAL : actions.defineLocal(); break;
case DEL_VAR : actions.deleteProperty(); break;
case DEL_THREAD_VARS : actions.deleteThreadVars(); break;
case ENUMERATE : actions.enumerate(); break;
case TYPED_EQUALS : actions.typedEquals(); break;
case GET_MEMBER : actions.getMember(); break;
case INIT_OBJECT : actions.initObject(); break;
case CALL_NEW_METHOD : actions.newMethod(); break;
case NEW_OBJECT : actions.newObject(); break;
case SET_MEMBER : actions.setMember(); break;
case GET_TARGET_PATH : actions.getTargetPath(); break;
case WITH : parseWith( in ); break;
case DUPLICATE : actions.duplicate(); break;
case RETURN : actions.returnValue(); break;
case SWAP : actions.swap(); break;
case REGISTER : actions.storeInRegister( in.readUI8() ); break;
case MODULO : actions.modulo(); break;
case TYPEOF : actions.typeOf(); break;
case TYPED_ADD : actions.typedAdd(); break;
case TYPED_LESS_THAN : actions.typedLessThan(); break;
case CONVERT_TO_NUMBER : actions.convertToNumber(); break;
case CONVERT_TO_STRING : actions.convertToString(); break;
case INCREMENT : actions.increment(); break;
case DECREMENT : actions.decrement(); break;
case BIT_AND : actions.bitAnd(); break;
case BIT_OR : actions.bitOr(); break;
case BIT_XOR : actions.bitXor(); break;
case SHIFT_LEFT : actions.shiftLeft(); break;
case SHIFT_RIGHT : actions.shiftRight(); break;
case SHIFT_UNSIGNED : actions.shiftRightUnsigned(); break;
//--Flash 6
case INSTANCE_OF : actions.instanceOf(); break;
case ENUMERATE_OBJECT : actions.enumerateObject(); break;
case GREATER : actions.greaterThan(); break;
case STRICT_EQUALS : actions.strictEquals(); break;
case STRING_GREATER : actions.stringGreaterThan(); break;
default: actions.unknown( code, data ); break;
}
}
}
protected void parseDefineFunction( InStream in ) throws IOException
{
String name = in.readString(mStringEncoding);
int paramCount = in.readUI16();
String[] params = new String[ paramCount ];
for( int i = 0; i < params.length; i++ )
{
params[i] = in.readString(mStringEncoding);
}
int codesize = in.readUI16();
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -