Welcome to Dream.In.Code
Getting Help is Easy!

Join 136,155 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,126 people online right now. Registration is fast and FREE... Join Now!




Embedding a flash player control

 
Reply to this topicStart new topic

> Embedding a flash player control, Utalize the flash player control for viewing movies and games

RodgerB
Group Icon



post 30 Dec, 2007 - 01:14 AM
Post #1


Embedding a flash player control.

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.

IPB Image

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 tongue.gif ).

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:
QUOTE


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.

CODE

''' <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:

CODE

''' <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:

CODE

gotoAndPlay(1)


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. tongue.gif

Have fun playing with your newly created control, and thanks for reading this tutorial.
Go to the top of the page
+Quote Post


Register to Make This Ad Go Away!


Fast ReplyReply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 12/1/08 11:13PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month