百度空间 | 百度首页 
 
查看文章
 
jswiff,生成flash文件的java框架
2007年09月20日 星期四 22:45

jswiff,生成flash文件的java框架

2007-04-13 17:12:34 / 个人分类:Java框架

JSwiff 是一款开源的,基于Java的操作Macromedia Flash file 的框架,可以创建,和操作Flash文件。

JSwiff 还提供了JSwiff Investigator,可以直接分析现有的SWF文件的结构,得到Tag层次的信息..

Jswiff是完全开源的,基于dual license (GPL/commercial).

官方网站是http://www.jswiff.com/

呵呵~看到这个消息兴奋吧,根据信息生成swf,难以想象,哈哈(虽然目前这个软件不是很完善,即使有flex可以根据xml生成swf)

其他不多说,喜欢的人自己可以到该网站去了解,下面我就拿出一个例子来。呵~~从官方那边修改过来的,我就不多做解释了(呵~人家说得很明白啦,虽然有点烦琐)

import java.io.FileOutputStream;
import java.io.IOException;

import com.jswiff.SWFWriter;
import com.jswiff.SWFDocument;
import com.jswiff.swfrecords.Rect;
import com.jswiff.swfrecords.RGBA;
import com.jswiff.swfrecords.Matrix;
import com.jswiff.swfrecords.tags.DefineFont2;
import com.jswiff.swfrecords.tags.DefineEditText;
import com.jswiff.swfrecords.tags.PlaceObject2;
import com.jswiff.swfrecords.tags.ShowFrame;

public class CreateSwf
{
public static void main(String[] args)
{
   String fileName = "test.swf";
   SWFDocument document = new SWFDocument();
   // first we define a font for the text
   // get a character ID for the font
   int fontId = document.getNewCharacterId();
   // use a standard font (e.g. Arial), we don't want to define shapes for each glyph
   DefineFont2 defineFont2 = new DefineFont2(fontId, "Arial", null, null);
   document.addTag(defineFont2);
   // get a character ID for our text
   int textId = document.getNewCharacterId();
   // dynamic text is a good way to go, we use DefineEditText for this
   // we don't care about bounds and variables
   DefineEditText defineEditText = new DefineEditText(
    textId, new Rect(0, 0, 0, 0), null);
   // we have set the text bounds to a zero rectangle;
   // to see the whole text, we set the autosize flag
   defineEditText.setAutoSize(true);
   // assign the font defined above to the text, set font size to 24 px (in twips!)
   defineEditText.setFont(fontId, 20 * 24);
   // set text color to red
   defineEditText.setTextColor(new RGBA(255, 0, 0, 255));
   // don't let viewers mess around with our text
   defineEditText.setReadOnly(true);
   // finally set the text
   defineEditText.setInitialText("弃天笑(soda) test!");
   document.addTag(defineEditText);
   // place our text at depth 1
   PlaceObject2 placeObject2 = new PlaceObject2(1);
   placeObject2.setCharacterId(textId);
   // place text at position (45; 10) (in twips!)
   placeObject2.setMatrix(new Matrix(20 * 45, 20 * 10));
   document.addTag(placeObject2); // place text
   document.addTag(new ShowFrame()); // show frame
   try
   {
    writeDocument(document, fileName);
   }
   catch (IOException e)
   {
    System.out.println("An error occured while writing " + fileName + ":");
    e.printStackTrace();
   }
}

private static void writeDocument(SWFDocument document, String fileName)
   throws IOException
{
   SWFWriter writer = new SWFWriter(document, new FileOutputStream(fileName));
   writer.write();
}
}

呵~记得把jswiff-8.0-beta-2.jar配置进环境变量哦。接着编译运行,就会产生一个test.swf文件啦。哈哈,赶快运行



类别:flash教程 | 添加到搜藏 | 分享到i贴吧 | 浏览() | 评论 (0)
 
最近读者:
 
网友评论:
发表评论:
姓 名:
网址或邮箱: (选填)
内 容:
验证码: 请点击后输入四位验证码,字母不区分大小写
      

     

©2009 Baidu