📜 ⬆️ ⬇️

C # WinForm / WPF + Adobe Flash

Hello everyone, this is my very first post, before that I was only a reader of this site. The topic of this post is the interaction of two different technologies, each of which operates in its own managed environment, Adobe Flash and Microsoft .NET.

At one time, for a single .NET project, I was looking for a replacement for GDI + graphics for WinForm. Flash technology was chosen as such an alternative. At that time, SilverLight was not familiar with it, and then organizing interaction with this technology for WinForm, through the WebBrowser component, failed.


After installing Adobe Shockwave Player, when Com is selected in Visual Studio, the visual component Shockwave Flash Object becomes available. This component has many properties for working with videos in swf format. In particular, if you specify a physical or network path to a movie in the Movie property, it will be displayed on the form, just as if it were in a browser. Then, through the SetVariable method (string Property, string Data), you can pass information from C # to any Flash property.
')

WinForm + Flash



Declaring a Flash external property in ActionScript 2.0 (1.swf)
//  getvar = function () { }; //   setvarData = function (value) { var Value:Number=Number(value); //    _root.gotoAndStop(Value+1); }; addProperty("MyObject", getvar, setvarData); 


Transfer information to a Flash movie from C #.
Before this, a component of the Shockwave Flash Object was set up in WinForm, named Flash, and its Movie property was set with the physical path to the movie 1.swf .
 int i = 1; Flash.SetVariable("MyObject",i.ToString()); 


WPF + Flash



Recently it became interesting how the application on WPF will look in conjunction with Flash. I searched the Internet, but unfortunately, if there is such information, it turned out to be very little.
As a result, I created a Flash component for this type of application.

XAML
 <UserControl x:Class="WindowsFormsApplication1.UserControl1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300"> <Grid Background="#FF00E100" Loaded="Grid_Loaded"> <WindowsFormsHost HorizontalAlignment="Stretch" Name="windowsFormsHost1" VerticalAlignment="Stretch" DataContext="{Binding}" Focusable="True" Margin="22,12,24,21" Background="#FF00005A" /> </Grid> </UserControl> 


Flash object
 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using AxShockwaveFlashObjects; using System.Runtime.InteropServices; namespace WindowsFormsApplication1 { /// <summary> ///   Flash /// </summary> public partial class UserControl1 : UserControl { public AxShockwaveFlashObjects.AxShockwaveFlash AxShockwaveFlash; public UserControl1() { AxShockwaveFlash = new AxShockwaveFlash(); InitializeComponent(); windowsFormsHost1.Child = AxShockwaveFlash; this.AxShockwaveFlash.VisibleChanged += new System.EventHandler(this.AxShockwaveFlash_VisibleChanged); } public string _Movie; public string Movie { set { _Movie = value; } get { return AxShockwaveFlash.Movie; } } private void AxShockwaveFlash_VisibleChanged(object sender, EventArgs e) { if (IsVisible) { try { if (Movie != null || Movie != _Movie) AxShockwaveFlash.Movie = _Movie; } catch { } } } private void Grid_Loaded(object sender, RoutedEventArgs e) { AxShockwaveFlash.Menu = false; } } } 


Transfer information to a Flash movie from C #, similar to WinForm
Before that, a UserControl1 component was set up with the name Flash and its Movie property was set with the physical path to the movie 1.swf .
 int i = 1; Flash.AxShockwaveFlash.SetVariable("MyObject",i.ToString()); 

Source: https://habr.com/ru/post/148373/


All Articles