-- online Search!

Flash in Visual Basic

by Seifer Tim   | filed under Flash and ActionScript

Archive

This is an archived tutorial about Flash. It's kept for history and may reference outdated tech.

TL;DR

You can use a Flash MX interface inside a Visual Basic program by publishing it as a SWF and dropping the Shockwave Flash component onto a VB form. Flash talks to VB through fscommand, and VB talks back by calling SetVariable on the component to change a variable in the Flash movie.

  • The Flash side is a button plus a dynamic text field with the instance name testField and the var testVar.
  • The Flash button's on (press) handler calls fscommand("setvalue", "Message A") to send a message out to the host program.
  • In Visual Basic, add the Shockwave Flash component through Project | Components, then drag it onto your form with a text box and a button.
  • Form_Load calls LoadMovie with the path to vbSample.swf, and the VB button calls SetVariable("testVar", "Message B").

This is an archived tutorial from the kirupa.com legacy collection. It covers software that may no longer be available, but it is kept online because the ideas still hold up.

One of the things that Flash is good for is making great user interfaces, which is a feature most other programming languages lack. I’ve discovered a way to make a user-friendly interface in Flash, and then use that interface inside a Visual Basic Application.

For an example of what you will be creating, download the following file, unzip it, and run the vbSample.exe program:

[ extract and open the file vbFlash.exe ]

Steps to Create Program

The following steps will guide you in creating the files you opened above:

  1. Start Flash MX, and make a new movie with any dimensions you would like. I used the dimensions 200px by 150px.
     

  2. Next, make a new Button Symbol, and name it anything you want:

[ create a new button symbol ]

  1. Make a rectangle in the first frame of the button, about 10 X 50 pixels, any color other than your background color. Align it to the center of the scene.
     

  2. Make a Key Frame in the next 2 frames of the button, and change the colors of the button for each frame:

[ modify the button for the up, over, and down states]

  1. Make a new layer, and put the word “Click” in that layer.
     

  2. Now, go back to the Scene 1, and drag an instance of the Button onto the scene.
     

  3. Drag a Text Field from the toolbox onto the scene, and give it the Dynamic Text property:

[ the text field and button ]

  1. Set the Instance Name to: “testField” and the var to: “testVar”.

[ the properties text field ]
 

  1. Click on the Button on the Scene, and open the “Actions” box.
     

  2. Type:

  on (press) {

fscommand("setvalue", "Message A");

}

[ copy and paste the above code ]

  1. Publish the movie as a SWF File, save, and exit Flash MX.


Visual Basic Instructions

Now, you will get to use the above animation in Visual Basic:

  1. Run Visual Basic, and start a new Standard EXE project.
     

  2. Go to “Project | Components”, then look for the component called: “Shockwave Flash” this comes with every Flash Movie Player install, so if you can view Flash movies, you should be fine:

[ the shockwave flash component ]
 

  1. Drag an instance of the Shockwave Flash component into your main form. Add a Text Box, and a button.
     

  2. Go to the Code Editor, and enter the following code:

  Private Sub Command1_Click()

Call ShockwaveFlash1.SetVariable("testVar", "Message B")

'This sets the _ value of the variable in the Flash Project.

End Sub

Private Sub Form_Load()

Call ShockwaveFlash1.LoadMovie(0, CurDir + "/vbSample.swf")

‘This loads the movie that was made into level 0 of the project.

End Sub

Private Sub ShockwaveFlash1_FSCommand(ByVal command As String, ByVal args _As String)

Text1.Text = args

'this catches the action sent by Flash, and uses it in the TextBox.

End Sub

[ copy and paste the above code ]

  1. That’s it! Make the EXE file, and save it in the same folder as the flash movie, then run the exe!

If you have any questions, please do not hesitate to post on the forums at: kirupaForum.

Seifer Tim

Before you go, here are a few things you can do:

  1. Keep reading

    Read the next article in the series, Flash MX 2004: Basic Tutorials.

  2. Ask a question

    Stuck on something, or curious about a detail we skipped? Ask on the forums, and we’ll help you out.

Just a final word before we wrap up. What you've seen here is freshly baked content without added preservatives, artificial intelligence, ads, and algorithm-driven doodads. A huge thank you to all of you who buy kirupa's books, became a paid subscriber, watch the videos, and/or interact on the forums.

Your support keeps this site going! 😇

The KIRUPA Newsletter

Thought provoking content that lives at the intersection of design 🎨, development 🤖, and business 💰 - delivered weekly to over a bazillion subscribers!

SUBSCRIBE NOW

Creating engaging and entertaining content for designers and developers since 1998.

Follow:

Popular

Loose Ends

:: Copyright © KIRUPA 2026 //--