⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 swfmerger.java

📁 java和flash混合编程
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		sprite.tagPlaceObject2( false, -1, 1, shapeId, new Matrix(), null, -1, null, 0 );
		sprite.tagShowFrame();
		sprite.tagEnd();
		
		//make sprite instance
		swf.tagPlaceObject2( false, -1, depth, spriteId, new Matrix(), null, -1, instanceName, 0  );
    }
    
    /** Get a required numeric attribute */
    private int getIntAttr( Element elem, String attrName ) throws Exception {
        try {
            return Integer.parseInt( elem.getAttribute( attrName ) );
        } catch( Exception ex ) {
            throw new Exception( "Element <" + elem.getTagName() + "> requires numeric attribute " + attrName );
        }
    }
    
    /** Get a numeric attribute, with default */
    private int getIntAttr( Element elem, String attrName, int defValue ) throws Exception {
        try {
            return Integer.parseInt( elem.getAttribute( attrName ) );
        } catch( Exception ex ) {
            return defValue;
        }
    }    
    
    /** Get a required string attribute */
    private String getAttr( Element elem, String attrName ) throws Exception {
        String val = elem.getAttribute( attrName );
        if( val.length() > 0 ) return val;
        throw new Exception( "Element <" + elem.getTagName() + "> requires attribute " + attrName );
    }

	/** 
	 * Test: 
	 * name of spec xml file is arg 0, 
	 * output is arg 1
	 * width  is arg 2
	 * height is arg 3
	 * rate   is arg 4
	 */
	public static void main(String[] args) throws Exception {
	    String specFile = args[0];
	    String swfFile  = args[1];
	    int width  = Integer.parseInt( args[2] );
	    int height = Integer.parseInt( args[3] );
	    int rate   = Integer.parseInt( args[4] );	    
	    
        SWFWriter writer = new SWFWriter( swfFile );
        writer.header( 6, -1, 
                       SWFConstants.TWIPS * width, 
                       SWFConstants.TWIPS * height, 
                       rate, 
                       -1 );
        new TagWriter( writer ).tagSetBackgroundColor( new Color(255,255,255) );
        
        SWFMerger merger = new SWFMerger( writer );
        merger.processMergeSpec( new File( specFile ) );
        
        writer.tag( SWFConstants.TAG_END, false, null );
    }
}



/** Extracts exported assets from a movie. */
class AssetExtractor extends SWFTagTypesImpl implements SWFTags {
 
    private String frameName;
    private byte[] actions;
    private int    frameNumber;
    private String frameLabel;
    private boolean finished = false;
    
    private TagParser parser = new TagParser( this );
    
    /**
     * @param frameName frame label or number
     */    
    public AssetExtractor( String frameName ) {
        this.frameName = frameName;
    }
    
    /**
     * Get the action 
     * @param filename movie file
     * @return null if not found
     */
    public byte[] getActions( String filename ) throws IOException {        
        SWFReader reader = new SWFReader( this, filename );     
        
        frameNumber = 1;
        frameLabel  = "1";
        
        reader.readHeader();
        while( reader.readOneTag() != SWFConstants.TAG_END && ! finished );
        
        return actions;
    }
    
    /** @see com.anotherbigidea.flash.interfaces.SWFTags#tag(int, boolean, byte[]) */
    public void tag( int tagType, boolean longTag, byte[] contents )
            throws IOException {

        switch( tagType ) {
        	case SWFConstants.TAG_SHOWFRAME:
        	    finished = frameLabel.equals( frameName );
        	    if( ! finished ) {
        	        actions = null;
        	        frameNumber++;
        	        frameLabel = Integer.toString( frameNumber );
        	    }
        	    return;
        	    
        	case SWFConstants.TAG_FRAMELABEL:
        	    parser.tag( tagType, longTag, contents );
        	    return;
        	    
        	case SWFConstants.TAG_DOACTION:
        	    actions = contents;
        	    return;
        	default: return;
        }
    }
    
    /** @see com.anotherbigidea.flash.interfaces.SWFSpriteTagTypes#tagFrameLabel(java.lang.String, boolean) */
    public void tagFrameLabel(String label, boolean isAnchor)
            throws IOException {
        frameLabel = label;
    }
    /** @see com.anotherbigidea.flash.interfaces.SWFSpriteTagTypes#tagFrameLabel(java.lang.String) */
    public void tagFrameLabel(String label) throws IOException {
        frameLabel = label;
    }    
    
    /** @see com.anotherbigidea.flash.interfaces.SWFHeader#header(int, long, int, int, int, int) */
    public void header(int version, long length, int twipsWidth,
            int twipsHeight, int frameRate, int frameCount) throws IOException {
        //nada
    }
}


/** Extracts frame actions from a movie. */
class ActionExtractor extends SWFTagTypesImpl implements SWFTags {
 
    private String frameName;
    private byte[] actions;
    private int    frameNumber;
    private String frameLabel;
    private boolean finished = false;
    
    private TagParser parser = new TagParser( this );
    
    /**
     * @param frameName frame label or number
     */    
    public ActionExtractor( String frameName ) {
        this.frameName = frameName;
    }
    
    /**
     * Get the action 
     * @param filename movie file
     * @return null if not found
     */
    public byte[] getActions( String filename ) throws IOException {        
        SWFReader reader = new SWFReader( this, filename );     
        
        frameNumber = 1;
        frameLabel  = "1";
        
        reader.readHeader();
        while( reader.readOneTag() != SWFConstants.TAG_END && ! finished );
        
        return actions;
    }
    
    /** @see com.anotherbigidea.flash.interfaces.SWFTags#tag(int, boolean, byte[]) */
    public void tag( int tagType, boolean longTag, byte[] contents )
            throws IOException {

        switch( tagType ) {
        	case SWFConstants.TAG_SHOWFRAME:
        	    finished = frameLabel.equals( frameName );
        	    if( ! finished ) {
        	        actions = null;
        	        frameNumber++;
        	        frameLabel = Integer.toString( frameNumber );
        	    }
        	    return;
        	    
        	case SWFConstants.TAG_FRAMELABEL:
        	    parser.tag( tagType, longTag, contents );
        	    return;
        	    
        	case SWFConstants.TAG_DOACTION:
        	    actions = contents;
        	    return;
        	default: return;
        }
    }
    
    /** @see com.anotherbigidea.flash.interfaces.SWFSpriteTagTypes#tagFrameLabel(java.lang.String, boolean) */
    public void tagFrameLabel(String label, boolean isAnchor)
            throws IOException {
        frameLabel = label;
    }
    /** @see com.anotherbigidea.flash.interfaces.SWFSpriteTagTypes#tagFrameLabel(java.lang.String) */
    public void tagFrameLabel(String label) throws IOException {
        frameLabel = label;
    }    
    
    /** @see com.anotherbigidea.flash.interfaces.SWFHeader#header(int, long, int, int, int, int) */
    public void header(int version, long length, int twipsWidth,
            int twipsHeight, int frameRate, int frameCount) throws IOException {
        //nada
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -