/*
Short and very basic guide to implementing the Macromedia Flash Player in a java application (or applet). I assume your system is some ind of windows, and that a java environment is installed. 0) Get the java environment from http;//java.sun.com. 1) Install the Macromedia Flash 5 program with the usual settings. (Download a trial fom http://www.flash.com if you don't have it.) 2) Find the directory named FlashApi inside the Macromedia directory. On my system the address is: C:\Program Files\Macromedia\Flash 5\Players\Flash Player Java(tm) Edition\FlashApi 3) In this directory there is a file named FlashApi.zip. Include that file in your classpath. 4) Reboot. 5) Make a directory named f.i. swf directly on the C-disk (or change the following commands to fit with your location...). Location: c:\swf 6) Copy this file - swfplayer.java - into the directory you created above. 7) Compile this file. 8) Unzip the contents of FlashApi.zip into the directory you created above - and make sure to keep the directory structure! 9) Make a flash movie in Macromedia Flash 5 - and make sure to export the movie as Flash 2!!!! (Flash 2 means no actionscripting, no alpha in your colors, and no mp3 - but you can use motiontweening and shapetweeing. Basically you can just export artwork. A file from Vecta 3D, for instance, is perfect for Flash 2.) 10) Name the flash movie you just made as "test.swf" and place it in the c:\swf folder you created above. 11) Open a commandline window and execute the application with: java -classpath c:/swf swfplayer c:/swf/test.swf If everything is done correctly, you will see a frame pop up - with the Flash 2 movie you just made: The movie will loop twice and then the frame will close. 12) Check out the html file: C:\Program Files\Macromedia\Flash 5\Players\Flash Player Java(tm) Edition\FlashApi\FlashApi.html - for a 13) Good luck! *** This code runs both as an application and as an applet. For an applet you need to pack all the files (the macromedia java player + the compiled swfplayer.class) in one jar-file. A nice tool for doing that is JZipper, which you can download from http://www.vegatech.net/jzipper/. Here is the HTML code for running the movie. <html> <body> <applet codebase="." width="10" height="10" archive="swfplay.jar" code="swfplayer.class"> <param name="flash_movie" value="test.swf"> </applet> </body> </html> */ import com.macromedia.flash.FlashApi; import com.macromedia.flash.Flash; import java.applet.Applet; import java.awt.Frame; import java.io.File; import java.io.FileInputStream; import java.io.BufferedInputStream; import java.net.URL; import java.net.URLConnection; public class swfplayer extends Applet implements Runnable { FlashApi flash_api; Frame f; Thread shutdown = null; boolean alive = false; BufferedInputStream bis = null; public swfplayer () { super (); } public void init () { this.setBackground (this.getBackground().white); try { setInputStreamAsUrl (getParameter ("flash_movie")); init2 (getParameter ("flash_movie")); } catch (Throwable t) { killThread (t.toString ()); } } private void init2 (String str) { f = new Frame ("playing flash movie: " + str); flash_api = new FlashApi(new Flash()); f.setSize (200, 200); flash_api.SetComponent( f ); flash_api.LoadScript ( bis ); flash_api.SetQuality(FlashApi.QUALITY_BEST, true); flash_api.SetLoop (false); flash_api.Startup(); startJS (); } public static void main(String[] args) { swfplayer s = new swfplayer(); try { s.setInputStreamAsFile (args[0]); s.init2 (args[0]); } catch (Throwable t) { System.out.println (t.toString ()); } } public void stop () { killThread ("stop called by browser"); } public void startJS () { if (shutdown == null) { f.show(); flash_api.Play(); shutdown = new Thread (this); alive = true; shutdown.start(); } } private void setInputStreamAsUrl (String url) throws Exception { bis = new BufferedInputStream ( new URL ( getCodeBase (), url ) .openConnection().getInputStream() ); } private void setInputStreamAsFile (String File) throws Exception { bis = new BufferedInputStream ( new FileInputStream ( new File (File) ) ); } public void run () { int num_loops = 0; while (alive) { try { shutdown.sleep (100L); } catch (Throwable t) {killThread (t.toString());} if (flash_api.CurrentFrame () == flash_api.TotalFrames () - 1) { num_loops ++; if (num_loops == 2) killThread ("done playing"); else flash_api.Play(); } } shutdown = null; } private void killThread (String str) { System.out.println (str); alive = false; try { System.exit (0); } catch (Throwable t) { f.hide (); flash_api.StopPlay (); System.out.println ("can't exit the system as an applet, will hide the frame instead..."); } } } /* Flash is a trademark of Macromedia (http://www.macromedia.com). Java is a trademark of Sun Microsystems (http://java.sun.com). This file copyright http://www.orgdot.com/javaopensource: you can copy, use, modify and distribute this code for educational, commercial or recreational use. all we ask is that you include this copyright notice in the source code you distribute. for compiled code, you will need to make accessible this copyright notice somewhere in the distribution, and/or via a link on the web. there are several reasons for this caveat - the most important being that open source is based on one main principle: what you find and use, others should also have access to. don't keep it to yourself! this software is provided by the author and contributors "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 or contributors 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. */