Google
 

Sunday, October 28, 2007

Running Flash Animation With Delphi

Running Flash animations with Delphi
How to display Macromedia Flash animations (swf) inside a Delphi application. Grasp the fundamentals of integrating Macromedia Flash animations and Delphi.


Scenario
Suppose you are developing some kind of a Delphi application designed to display various graphics file formats. By default, Delphi lets you handle and show BMP, JPG, WMF and other "standard" picture file formats, and even animations. If you want to take you application to the next level, sooner or later, you'll want to include an option to play Flash animations. Macromedia Flash animations (*.swf) are those fancy movies you see everyday while surfing the Internet.

How to prepare for Flash animations
To display a Flash animation in a Delphi application, you'll need to import Macromedia Flash ActiveX control. The Flash ActiveX is titled 'SWFLASH.OCX' and it will probably be located somewhere inside the C:\Windows\System\Macromed\Flash folder.

First, let's see how to import the control into Delphi - of course, you only need to do this once:

  1. Start Delphi and select Component | Import ActiveX Control... from the main menu
    Delphi - Component - Import Activex
  2. Look for the 'Shokwave Flash (Version x.x)' and simply click on Install.
    Delphi Import ActiveX
  3. Select the Component palette location in which you want to place selected library. Maybe the best is to leave the ActiveX option selected.
  4. Click on Install.
  5. Select a package where the new component must be installed or create a new package for the control. By default, Delphi will propose the dclusr.dpk package.
  6. Click on OK.
  7. Delphi will prompt you whether you want to rebuild the modified/new package or not. Click on Yes.
  8. After the package is compiled, you'll get a message saying that the new TShokwaveFlash component was registered and already available as part of the VCL.
  9. Close the package detail window, allowing Delphi to save the changes to it.
  10. The component is now available in the ActiveX tab (if you didn't change this setting in step 4)
How to play Flash animations with Delhi
You are now ready to create your fist Flash enabled Delphi application. Here's how:
  1. Select the ActiveX tab on the Component palette.
  2. Pick the TShokwaveFlash component.
  3. Drop the component on a form.
  4. Select the component you just dropped on a blank form.
  5. Using the object inspector, set the Movie property to the name of an existing swf file on your system. Note that you must set it with the full path name.
  6. Make sure that the Playing property is set to True.
  7. Run the project, and here it is! A sample swf file is running below, though you do not see it running :)
    Flash in Delphi application

Flash to the max
Now, if you need to distribute you own very special Flash movie with your application, one way to go is to include a swf file inside your Delphi application exe file, as a resource.

If there is a need to register an ActiveX control on your user machine (while deploying your application) than you need to make sure the user has the ocx you need. See how to "Registering DLL and ActiveX controls from code"

And here's how to work with other properties and methods of the Flash component: ActiveX and Macromedia Flash.

No comments: