Welcome to this tutorial on embedding a flash player control. In this tutorial, we will learn how to add one to a form, play a movie, and position itself correctly in its container. This tutorial will require that you have a flash player installed on the computers you would like to use it on. In this tutorial, I am using Adobe Flash Player 9.0 r46, so results may vary on other versions, according to technological advances. We will also be covering going to a specified frame much like the gotoAndPlay() method, and dynamically changing the movie.
1) Adding the control to the form.
Visual Studio makes it easy to add the Flash Object to the project. Right Click in the General Category in the Toolbox, and a Context Menu will appear. Select "Choose Items...".
The Choose Toolbox Items dialog box should appear now. Click the COM tab at the top of the dialog and search down the list until you find "Shockwave Flash Object". Tick the Checkbox, and click Ok.
You should now have a Shockwave Flash Object control in the toolbox. Drag one onto the Form, and rename it to flashPlayer (sorta a personal preference thing really, I just can't stand how ugly AxShockwaveFlash1 looks ).
2) Playing a movie.
Playing a movie is very simple with the Flash Player, infact there really isn't much to it at all, its just changing the Movie property.
For the purpose of this example, lets make the Flash Player play Line Rider. Set the Movie property to:
We will now have the control playing this movie. But why is it not stretched to see the whole movie you ask? This will be explained in the next section.
3) Stretching the movie to see all the goods.
Sometimes when we load a new movie, the ScaleMode property changes. If you want it to show the whole movie for the control, you will need to have the ScaleMode equal zero. I have created this simple wrapper, for dynamically changing the movie and keeping it the right view.
''' <summary> ''' Sets the movie and keeps it stretched. ''' </summary> ''' <param name="strMovie">The path to set the player to view.</param> ''' <remarks></remarks> Public Sub setMovie(ByRef strMovie As String) flashPlayer.Movie = strMovie flashPlayer.ScaleMode = 0 End Sub
Now resize the form and control in a comfortable playing manner if you haven't already, and continue to the next step.
4) Our own gotoAndPlay() method.
The Flash Player control has its own FrameNum property. In our case in Line Rider, we can make it skip those first two frames, one for the main scene and one for a tutorial about how to play. To do this, we can't just set the FrameNum property in the form designer, it seems to be all show and no go.
To combat this issue, we will change it programmatically. Here is the gotoAndPlay() method we will be using:
''' <summary> ''' Go to the frame number specified. ''' </summary> ''' <param name="frame">The frame number to goto.</param> ''' <remarks></remarks> Public Sub gotoAndPlay(ByRef frame As Integer) flashPlayer.FrameNum = frame End Sub
Add the following code to the Form1.Load event:
This will skip straight to the game, cutting the crap if you will. I'm sure you can think of many other awesome ways to do stuff, such as game cheating etc, but i'll leave that to you to think of.
Have fun playing with your newly created control, and thanks for reading this tutorial.