无法使用Transform API播放swf文件

时间:2014-06-30 20:09:48

标签: java swing flash

我尝试使用Transform API Transform SWF for Java播放swf文件,但失败了。我厌倦了movie.decodeFromFile(),loadMovieNum()等等。

Movie movie = new Movie();
movie.add(Place2.show(2, 3, 2, 2));

//movie.decodeFromFile(new File("test.swf"));
loadMovieNum("test.swf",1); 

如果我找到此任务的示例代码,那将会很棒。

(更新)

@Josef:您只是从网站上复制/粘贴代码。其实我想知道如何播放swf文件。代码包含其他不必要的东西,如字体,字体颜色等,不需要播放swf文件。

我认为只有以下声明与播放swf文件有关 -

Movie movie = new Movie();
movie.add(Place2.show(text.getIdentifier(), layer++, xpos, ypos));
movie.add(ShowFrame.getInstance());
movie.encodeToFile("example.swf");

但我的问题是 - 我是否不需要使用JPlane添加此电影对象来播放swf文件?

1 个答案:

答案 0 :(得分:0)

以下是使用变换播放swf的示例:

int uid = 1;
int layer = 1;

final String str = "The quick, brown fox jumped over the lazy dog."
final Color color = WebPalette.BLACK.color();

final String fontName = "Arial";
final int fontSize = 24;
final int fontStyle = java.awt.Font.PLAIN;

// Load the AWT font.
final AWTDecoder fontDecoder = new AWTDecoder();
fontDecoder.read(new java.awt.Font(fontName, fontStyle, fontSize));
final Font font = fontDecoder.getFonts().get(0);

// Create a table of the characters displayed.
final CharacterSet set = new CharacterSet();
set.add(str);

// Define the font containing only the characters displayed.
DefineFont2 fontDef = font.defineFont(uid++, set.getCharacters());

// Generate the text field used for the button text.
final TextTable textGenerator = new TextTable(fontDef, fontSize * 20);
DefineText2 text = textGenerator.defineText(uid++, str, color);

// Set the screen size to match the text with padding so the
// text does not touch the edge of the screen.
int padding = 1000;
int screenWidth = text.getBounds().getWidth() + padding;
int screenHeight = text.getBounds().getHeight() + padding;

// Position the text in the center of the screen.
final int xpos = padding / 2;
final int ypos = screenHeight / 2;

MovieHeader header = new MovieHeader();
header.setFrameRate(1.0f);
header.setFrameSize(new Bounds(0, 0, screenWidth, screenHeight));

// Add all the objects together to create the movie.
Movie movie = new Movie();
movie.add(header);
movie.add(new Background(WebPalette.LIGHT_BLUE.color()));
movie.add(fontDef);
movie.add(text);
movie.add(Place2.show(text.getIdentifier(), layer++, xpos, ypos));
movie.add(ShowFrame.getInstance());

movie.encodeToFile("example.swf");

<小时/>

修改

Embed .swf file to JFrame

希望有所帮助!