Click here to Skip to main content
Click here to Skip to main content

Playing Flash Files (SWF) in C# Form

, 10 Aug 2013
Rate this:
Please Sign up or sign in to vote.
In this tip for beginners, we will review how to play a shockwave file (.SWF) in our form in the easiest and fastest way by using Shockwave flash object component.

Introduction

Maybe sometimes you want to play a shockwave flash file (.swf format) in your C# or VB Visual Studio form. There are many ways to do it, but the easiest way is using its component which is available for use. In this tip for beginners, we will review how to play a shockwave file (.SWF) in our Visual Studio form with the easiest and fastest way by using Shockwave flash object component.

This component is located at %systemroot%\system32\macromed\flash9c.ocx and if you can't find it, you must install the latest version of Adobe Macromedia Flash Player. With this component, you can play all .swf files in order to show them in your projects and not reference which kind of flash file you use (a flash game, a flash banner or something else).

Using the Code

So for doing what we want, we must follow the steps given below:

  1. Add Shockwave flash object to Toolbox (with brief explanation): At first, we need to add Shockwave flash object component to our Toolbox. Generally, for adding a component to toolbox, we can right-click on Toolbox window and then click on choose items.

    Next in Choose toolbox items window, we can find and add each component we want and in this tip, we must go to Com components tab and add Shockwave flash object from there to toolbox. Now, you can see that component in your toolbox.

  2. Add to form: Now you must Drag & Drop the component to your form.

    Tip: One of the famous errors which you can be forced into is error in importing your component to your Visual Studio form. If you are forced to “Failed to import the ActiveX control. Please ensure it is properly registered” error, rebuilding project can help you. This error usually happens when you drag and drop the ActiveX component to a form and rebuilding the project will help you to remove this error. But, I found a solution here for solving this problem forever. Also, if you need a way for registering it manually, this link which I found can help you.

  3. Setting address of swf file to your object: Now you can set your swf file address to your object in any way you want. For example, in C#, you can use this code for playing sample.swf flash file:
    axShockwaveFlash1.Movie = Application.StartupPath + @"\sample.swf";  

    Some simple commands of this component are:

    Playing Flash: AxShockwaveFlash.Play()
    Pausing Flash: AxShockwaveFlash.Stop()
    URL Source of Flash file: AxShockwaveFlash.Movie = FilePath & "\FileName.swf" 

    Other commands properties of this component are:

    1. Loop: which in "True" mode helps to playing flash file continuously
    2. Quality: which in default value shows your flash file in its best quality
    3. Menu: which you can disable right click menu of flash object (settings) by it
    4. Framenum: by this, you can choose your start frame of your swf file
    5. EmbedMovie: make your flash file source embed to your solution
    6. BGColor: background color of your file when it starts to play
    7. AlignMode, AllowFullscreen, CTLScale, SAlign, WMode are used for positioning and setting view mode

In Other Languages

Originally, this beginner tip was published in Persian language on my website, then I translated it to English because I thought it might be helpful for people who have just started coding in C#!

Iranian friends can find the original article in Persian on Sourcenevis.

Sample Solution

A project of this tip can be downloaded here.

In this sample, I added a Shockwave flash object to the form and then created play, stop commands for them. Also, I link URL of flash file into debug folder which is contained with the main EXE file.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Amir Nasrollahi
CEO
United States United States
- Founder & CEO at Artificial Intelligence Developers - (AID)
- CSM Technology Founder
- Research and Development in the field of "Cloud Computing" and various topics of cloud science, artificial intelligence, speech and image processing, any platform projects design and construction.

Comments and Discussions

 
GeneralMy vote of 5 Pinprofessionalketan italiya12-Aug-13 21:46 
GeneralRe: My vote of 5 PinprofessionalAmir Mohammad Nasrollahi12-Aug-13 23:06 
QuestionImage missing PinprofessionalMaimonides11-Aug-13 1:31 
AnswerRe: Image missing PinprofessionalAmir Mohammad Nasrollahi11-Aug-13 1:56 
GeneralMy vote of 5 PinprofessionalEhsan Azami10-Aug-13 8:43 
AnswerRe: My vote of 5 PinprofessionalAmir Mohammad Nasrollahi10-Aug-13 8:44 
GeneralMy vote of 5 PinprofessionalReza Khan Mohammad10-Aug-13 8:36 
AnswerRe: My vote of 5 PinprofessionalAmir Mohammad Nasrollahi10-Aug-13 8:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 10 Aug 2013
Article Copyright 2013 by Amir Nasrollahi
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid