Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use C# with AIR?

I have some basic experience in making Flex sites, but I think I have more use for Flex in making a desktop AIR application.

Anyway, I was wondering if it is at least possible to use C# alongside Actionscript/AIR? I can't find any example of this.

Also, can I use custom Flash components in a Flex app? I know I can use Javascript components.

Thanks

like image 914
GurdeepS Avatar asked Apr 20 '09 22:04

GurdeepS


4 Answers

Your options with AIR are limited to HTML/JS, Flash/ActionScript or Flex. There's no support for other languages and frameworks.

like image 153
John Sheehan Avatar answered Oct 04 '22 03:10

John Sheehan


You can create a C# console application and call this application from AIR.

var file:File = File.applicationDirectory;
file = file.resolvePath("CSharpConsoleApplication.exe");
var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
nativeProcessStartupInfo.executable = file;
nativeProcessStartupInfo.arguments.push("-arg");
var process:NativeProcess = new NativeProcess();
process.addEventListener(NativeProcessExitEvent.EXIT,onProcessDone);
process.start(nativeProcessStartupInfo);

In this way we have a C# application with AIR interface.

like image 37
Alex Avatar answered Oct 04 '22 03:10

Alex


Slukse is correct -- it depends on what you mean by "alongside."

Obviously you can't compile C# code into a SWF -- that much we know. But you can certainly embed (as davr suggests) an ActiveX control into a .NET Forms app, load the SWF into that control, and use the ExternalInterface API to bridge the C# code running in the desktop app and the ActionScript code running in the SWF. If by alongside you mean writing server-side C# code to render data consumable by the Flex app, then of course, you can do that, too -- there's plenty of documentation out there covering how to connect a Flash or Flex (or AIR, by extension) app to Web Services of a variety of flavors, including the relatively new-ish WCF stuff.

Another way to go would be to run a standalone C# desktop app (e.g., a service, console app or the like) and have that app listening over a certain local port -- then have your SWF talk to that app using the Socket classes. I'm doing something like this now (with Java, not C#, but the idea's the same) for a personal project.

like image 28
Christian Nunciato Avatar answered Oct 04 '22 02:10

Christian Nunciato


If by 'alongside' you mean using c# as middleware to connect to your database (probably SQL Server), or to perform remote calculations then yes you can. You can connect to a c# service using remote objects. The midnight coders produce a product called WebORB that is fairly simple to use. Version 3.4 was a totally free version that should suffice if you are building desktop applications in Air. The next two versions are not free but basically offer no real advantage to you.

like image 26
slukse Avatar answered Oct 04 '22 03:10

slukse