How to use library of other languages in Action Script 3? - actionscript-3

Is there any way to use the library of other language in Action Script 3 ?
For C/C++
I learned that we can use Alchemy: http://labs.adobe.com/technologies/alchemy/
But for other languages (here I mean Ruby or Java), can I use their libs via AS3 ?

Alchemy is a cross-compiler from LLVM to ABC, if the language you are interested in can compile to LLVM, then, in theory, you can compile to ABC. So, Alchemy supports (with some tweaks) also C# or Java (but you will have to spend some time getting them to work together, there's no out of the box solution).
AIR (which is a desktop variant of Flash) can use something called "NativeProcess" which means that granted the operating system can execute the code in the library, then you can do so by creating a new process that calls the function from the library you need.
In AIR, again, there's a new feature called ANE (AIR Native Extensions) - this allows you to bind AIR more tightly to the native code. But, it doesn't need to be native as in object files only, it should be something the underlying system can execute. But I have to confess, I never tried creating any such extension, so my knowledge of it is theoretical.

No you can not use Ruby or Java code/libraries in Flash. Alchemy only allows you to use C and C++ libraries. The only way is to port those libraries to ActionScript, or maybe the library you want to use has already been ported to AS3.
It is also possible that there is something similar in AS3. You could ask another question here or on an Flash forum if anyone knows if the library you need has an equivalent in flash.

Related

Is there any way to run two instances of flash professional debug

After already searching the site for the answer to the question, I've found this:
Is it any way to run two instances of debuggers?
I need the Flash Professional CS5.5 version of the answer to this question.
Basically - I need to know if there's a way to debug 2 different .fla files in Adobe Flash Professional CS5.5 at the same time. One of them implements the Adobe AIR framework (for using the SocketServer class), the other is a standard AS3 project. It'd be nice if I could debug the client-server interaction easily using the IDE rather than using extensive means to do so.
Anyone have any ideas? Thanks.
This is not an answer to your question but a suggestion to take a different approach.
The Flash IDE and it's debugger are inadequate but for most trivial programs. Variable inspection and breakpoints work randomly and it's next to impossible to drill down into more complex objects. Flash IDE is all right for creating the visual resources for Flash programs but for any serious coding, it just falls on its face. The compiler included with the Flash IDE is also very poorly written and generates unoptimized code.
I'd suggest to switch over to using FlashDevelop - it's a free, open source IDE that runs on top of the Flex and Air SDKs and uses a better compiler that performs more optimizations. (You can mark functions for inlining, etc.) The debugger - while not Visual Studio - is much, much better than the IDE: breakpoints work and object properties can be inspected easily.
Because FlashDevelop is geared towards coding, you can create a project in it with multiple source files, define your resources and then compile to multiple platforms. Compilation is usually fast with hundreds of source files (don't import every type in every package) and you can do debug/release builds. If you can port your code from Flash to FlashDevelop, you'll have a much easier time managing your project.

What is Cocos2d-JS?

Cocos2d-JS is Cocos2d-x engine's JavaScript version that includes
Cocos2d-html5 and Cocos2d-x JavaScript Bindings. It equips your game
with cross-browser and cross-platform abilities, accompanied by full
Cocos2d-x features and simplified JavaScript friendly APIs.
I understand that you write JS and it works every where, but how it is done? I want to understand this diagram: http://www.cocos2d-x.org/wiki/Getting_Started_Cocos2d-js As I understand cocos2d-html5 is the same thing as cocos2d-x but it is in JS and based on WebGL. If this is true then what is Cocos2d-JSB? Does it compile JS script to native code? Or is it a JS extended interpreter, that understands more than native interpreter and can interpret cocos2d specific commands?
As I understand cocos2d-html5 is the same thing as cocos2d-x but it is
in JS and based on WebGL. If this is true then what is Cocos2d-JSB?
I believe the JSB appended to cocos2d-x JSB simply means: cocos2d-x JavaScript Bindings
The module that does the translation / mediation between two programming languages is commonly called a "binding". The JSB is just a small aspect of cocos2d-x that allows users to run apps written in cocos2d-js Javascript via the cocos2d-x C++ rendering engine.
Note that cocos2d-html5 is not exactly the same as cocos2d-x. It provides similar functionality than cocos2d-x but runs only in a web browser. Obviously cocos2d-html5 has no functionality for touch or accelerometer input, and other restrictions when it comes to saving and loading files, for instance.
Does it compile JS script to native code? Or is it a JS extended interpreter, that understands more than native interpreter and can interpret cocos2d specific commands?
The JSB simply maps between the Javascript API and the C++ cocos2d-x versions of classes, methods, identifiers and what not.
I don't know whether it compiles Javascript to native code.
The gist of this:
cocos2d-js provides a programming interface (API) in Javascript that produces the same results whether you run it in the browser via cocos2d-html5 or on other (mobile) platforms via cocos2d-x.
Cocos2d-x uses SpiderMonkey, the Firefox JS virtual machine (VM), to
execute JS code.
The JS VM is extended to support all the cocos2d, Chipmunk and CocosBuilder Reader APIs. So, when you create a CCSprite in JS, you
are actually creating an C++ CCSprite. When you create an action in
JS, you are actually creating an C++ action, when you create a
particle system in JS, you are actually creating an C++ particle
system… and so on. This approach is about 10x ~ 20x faster than HTML5
games even when they use accelerators like directCanvas Basically all
the cocos2d, Chipmunk or CocosBuilder Reader APIs are going to perform
almost at native speed. But you should pay attention to the following
scenarios: The performance could be slow down while the garbage
collector is run. Workaround: Do not create many JS objects. Reuse as
many as possible Having a complex main loop could slow down the
performance. Workaround: Profile your JS code, and if you can’t
further optimize it, write the expensive parts in C++ and create JS
bindings for those functions.
This is from wiki. So the JS interpreter is extended to understand cocos2d api command such as create Action or create Sprite.

Coming from a Flash Builder background, how can I import a library into IntelliJ IDEA?

the only IDE I've used for many years was Flash Builder. Sadly the 4.7 version is in a poor state, so, I started looking at other IDE's lately.
I'm trying IDEA, but I don't know how to add a library to my project.
In FB it was simple, I go to the compiler settings and I just add a folder or swc. But here, it seems like there are 2 options, one under the "Libraries" tab and other is creating a new module, however, this new module requires a main app, SDK, and a lot of other stuff that doesn't make any sense to have in a library.
So, what is the equivalent of adding a library path here?.
Thanks.
"Libraries" is the correct way to do it. There are two kinds of libraries: libraries and global libraries. Global libraries can configured once and used in every project. Libraries are configured for each project. See http://www.jetbrains.com/idea/webhelp/configuring-project-and-global-libraries.html

Should we place C code in Static library or Runtime component?

We're moving to Windows Phone 8. But since many good libraries out there are in pure C. So what is the best way for Windows Phone C# application to consume this C library?
Place C code in WP Static library. Then reference it from WP Runtime
component
Place C code in WP Runtime component
What is the best practice ?
There isn't any real difference between the two approaches. A static library is nothing but a collection of .obj files, the exact same kind of .obj files that you'll get from approach #2. After the linker is done, there won't be any difference in the result.
That's when everything is perfect, an ideal that can be very difficult to achieve when you use open source C code. An advantage of a static .lib is that it improves build time, not having to re-generate the .obj files. But that's also their disadvantage, you'll shoot your foot if you use a .lib that was created by somebody else and he didn't use the same compiler version or compile options. The simplest example of such a trap is building your Debug version and the .lib was built for Release. Or if it uses winapi functions that are verboten in a Phone app, pretty common. So #3 is the best way to avoid problems, build the .lib yourself so you can control all the compile and link settings. Do beware however that it can be very difficult to get open source C code to build, it often comes with a very extensive configuration script, designed to deal with the differences between the many architecture and Unix variants.

Is there a Library for dealing with OpenSoundControl in ActionScript

I would like to send and receive OpenSoundControl in an AIR application, on the opensoundcontrol.org website I have found existing libraries for many languages, but none for Action Script so far, do you know of one that could be readily used?
Tuio AS3 has nice classes for OSC. Check this example http://bubblebird.at/tuioflash/guides/sending-osc/