views:

198

answers:

5

Is it possible to use any IPC mechanism for calling a c++ api from Adobe Flash actionscript? Are there any good examples?

Update: I primarily want it for desktop apps now i.e Adobe's/or anyuone else's desktop runtimes

A: 

It really depends on what the "API calls" you refer to are. If they refer to IPC mechanisms, generally the answer is no. You can compile the code, but you will not have the implementation to support these calls. If you are using sockets, you can implement support for that in Flash although Alchemy does not currently support the socket() API. Does this help?

via

Eugene
A: 

Some time ago I read about ActiveX support in flash. Perhaps you could write a ActiveX wrapper around your C++ Api and call it this way. With Air 2.0 you have another possibility - you can invoke external programs. If you write a command line wrapper around your api you could call it that way.

David Feurle
@david, i like your Air 2.0 solution, can you direct me to some simple code samples?
iceman
@iceman see here: http://mchristoff.com/2009/12/using-the-air-2-0-nativeprocess-api-to-control-mplayer/http://www.adobe.com/devnet/air/flex/quickstart/interacting_with_native_process.html
David Feurle
+1  A: 

Not from the flash player, as it would very likely violate its security model. You can call C++ from the Tamarin VM, which for example mod-actionscript is doing. An option would be to pass your calls to an AS3-server, call some C++ functions there and send back the result. Another option is to cross-compile the C++ code to AVM2 using alchemy. But if you want to call C++ to access features on the client machine not available from the flash player (file system access, UDP or whatever), then there's no way.

edit:
Ok, I suppose there are the following options:

  • have a look at the flash.accessibility package and solve it with AS3 only
  • create a C++ daemon running in the background, which can have bidirectional communication with flash through
    • a local socket (you'd bind a port in the daemon and the flash client would connect to it) with a custom protocol
    • a LocalConnection. This looks a little better from the AS3 perspective, but requires a little hacking on the C++ side, since you need to get hold of the connection and implement the protocol (pointers here)
  • use an alternative runtime: adobe air, zinc, swhx (requires haXe though and the "backend" is neko, but neko can easily be extended)
back2dos
@back2dos: hence what you are saying is that I can use the as3 language, but a different flash player than Adobe?? which are the ones available?
iceman
@iceman: well, there's lightspark, which is open source, so I suppose, you could modify it for your needs. Other than that, I see no options. Maybe, if you explained, what you're trying to accomplish, I could be of more help.
back2dos
@back2dos:I'm planning to make more accessible interactive desktop apps..so combine the rich UI of flash and the coding power of c++..so I want to use a text-to-speech engine to read out to the user what is written on the screen..
iceman
@iceman: post updated
back2dos
@back2dos:thanks a lot..I think using the Flash package is not viable as I have to make own voices. I'm not sure if the LocalConnection object supports Flash Player 10 or AIR. I'll be interested in the socket creation method you've mentioned. but it might be difficult to develop such middleware (CORBA?)from scratch..maybe I'm misinterpreting.Could you give more hints on that?
iceman
@iceman: assume the best possible way could make these C++ calls. What would you do then (example/pseudo code)?
back2dos
+1  A: 

It is not possible from the browser-player. From an AIR application, you can use Socket API to do IPC.

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/Socket.html?allClasses=1

Seeker
@Seeker: thanks a lot, I primarily want it for desktop apps now..do you know any high level API than the socket API to communicate between c++ and as3/mxml?
iceman
As far as i know IPC means sockets/shared mem/msgq etc. So according to ur requirement only supported thing is Sockets. Anything higher than these IPCs will be slower and unnecessary, for e.g. higher levels of sockets are http etc., which you may not want to use.
Seeker
A: 

If you target the Adobe AIR runtime, you can leverage the NativeProcess API that was introduced in AIR 2.0. This API allows you to spawn external processes and communicate with them via stdin and stdout.

If you're feeling adventurous and want to do something undocumented and completely unsupported, you can tap into the LocalConnection internals by interacting with the memory mapped file of the Flash Player. There's more detail on the osflash.org/localconnection site. This approach has some limitations and isn't supported. I don't recommend it.

As mentioned in some other answers, you can also use a socket connection to send/receive data.

darronschall