Insert a flash object in the WPF Project

Source: Internet
Author: User
How to embed flash (ActiveX) in WPF) Background

A recent partner wants to embed the previous flash into a brand new WPF Application and.. Net 3.0 rich user experience combined with Flash animation to better serve its users.

Embedding flash is equivalent to embedding an ActiveX control. Some tricky points should be noted during the embedding process. The steps for embedding flash control in WPF application are briefly described below, and remind you of some issues that need attention.

Development Environment

Visual Studio 2008 beta1 (code name: Orcas), Windows Vista, Flash Player 9,

Method

1. Create a WPF application.

First, create a WPF application named flashinwpf

2. Set the window attribute.

Modify the window attribute in XAML, add the loaded event, and set the X: name of the default grid to "flashgrid". The Code is as follows:

<Window X: class = "flashinwpf. window1"
Xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Xmlns: x = "http://schemas.microsoft.com/winfx/2006/xaml"
Title = "flash in WPF" loaded = "windowloaded" Height = "500" width = "600">
<Grid X: Name = "flashgrid">
</GRID>
</WINDOW>

3. Create a Windows Forms control library

As a display layer project, WPF application cannot insert COM component itself. Therefore, you need to use Windows form to introduce ActiveX control.

 

4. Insert Shockwave Flash Object

Right-click the toolbox and choose "choose items..." to add COM components.

 

Tricky point:In COM component, a Macromedia Flash factory object is also linked to C:/Windows/system32/macromed/flash/flash9c. OCX, but do not select this component here. Otherwise, "failed to import the ActiveX Control" may appear. You can use regsvr32.exe flash9c. OCX registers flash9c in the command line. OCX control. The following registration success prompt is displayed:

 

 

5. Create a Flash Object

After a Shockwave Flash Object is added, an object named axshockwaveflashobjects is automatically added to the Flash control project.

The axshockwaveflash1 object is added by default in usercontrol1.designer. CS.

Private axshockwaveflashobjects. axshockwaveflash axshockwaveflash1;

6. Compile flash Control

 

7. Add reference in flashinwpf

Added axinterop. shockwaveflashobjects. dll compiled in Flash control.

 

Add DLL used to integrate ActiveX in Windows form

 

Add windows form DLL

 

8. Modify the codebehind of the window.

The code and comments of window1.xaml. CS are as follows:

Private void windowloaded (Object sender, routedeventargs E)
{
// Create a Host Object
System. Windows. Forms. Integration. windowsformshost host = new system. Windows. Forms. Integration. windowsformshost ();

// Instantiate axshockwaveflash1
Axshockwaveflashobjects. axshockwaveflash axshockwaveflash1 = new axshockwaveflashobjects. axshockwaveflash ();

// Load. axshockwaveflash1
Host. Child = axshockwaveflash1;

// Embed the Host object into flashgrid
This. flashgrid. Children. Add (host );

// Set the relative path of the. SWF File
String swfpath = system. environment. currentdirectory;
Swfpath + = @ "/sample.swf ";
Axshockwaveflash1.movie = swfpath;
}

 

9. Add a. SWF File

Select always copy to output directory to use the WPF applicaiton to call the flash

 

10. Success

 

Click here to download this project file.

Tips

You can use the powerful Object Browser in Visual Studio to view various flashobjects methods and abstract classes, as shown in

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.