views:

548

answers:

7

I am developing a Flex / Flash application which talks to an ASP.Net / C# backend. Is there any way I can share code between the two?

The server provides a reasonably interesting domain model which the client is designed to maniuplate. Ideally I would like to be able to define this domain model once and have both sides use it for consistency. I am after all the benefits that come with being DRY.

I'm new to Flex but the sort of thing I had in mind was some intermediate language that compile to both C# and ActionScript.

Update

I currently have a basic REST style web service which sends XML serialized versions of the objects down the wire to Flex. This works fine but what I am really interested in is being able to share simple business logic that goes along with these objects. There are certain business rules that need to be processed on both the server and the client and is possible I would prefer not to have to call back to the server for performance reasons.

A: 

Check out http://www.fluorinefx.com/ (It is open source flash remoting). I have used it extensively to call web services written in C# from ActionScript, and it works great. Once nice thing is that your c# can return a DataSet (or something similar) and the Flourine framework will convert that into an object ActionScript understands.

Joe
A: 

Update

You can pass objects through the use of Lists, but what you're really passing through is just the data.

You can't really pass a 'method' to a client.

  1. They don't necessarily have to honor it. Once they're in possession of the data, you can't control whether they honor the methods you passed or not.
  2. You wouldn't want to trust anything they send back to you subsequently.

I think the issue is with the set-up.

You can process anything you want on the client side using ActionScript, and you'll just have to put the business logic you want to manipulate in the ActionScript side of things if you want to do it on the client-side.

Olde Answer

I use Flex and C# together through the use of a web service layer.

You may want to look at creating web services to have flex talk to your C# code.

George Stocker
A: 

Not that I'm aware of, C# is essentially a strongly-typed, compiled language and ActionScript is a loosely-typed, interpreted language. Chalk and cheese I'm afraid.

Lazarus
A: 

What if you serialize the objects to XML and send them to Flex....that would at least let you share the data

PSU_Kardi
+1  A: 

I'd hack together a domain model specification and have it generate models in both languages. But that's probably not the most time-effective thing to do.

Wouter Lievens
Not the easiest thing to do but it's the closest to what I'm trying to acheive so will have to do for the accepted answer.
Generic Error
+1  A: 

I faced this problem as well, so I wrote a C# to ActionScript converter.

http://cs2as.codeplex.com/

Write your logic in C#, and add this utility as a post-build step. Then your business logic will be available in both environments. It works very well for me - I'm using it to share over 30,000 lines of code.

fickerra