New Two-Part Tutorial On AIR 2.0 NativeProcess

I recently uploaded a two-part tutorial that explains how to use the new NativeProcess API in Adobe AIR 2.0. With this API you can communicate with native code to get deeper access to the host operating system. In the first part, I create a command-line screenshot application using Visual Studio and C#. In part two, I create an AIR-based front-end for the C# application using the NativeProcess API.


Commentary

  1. Rob Fox says:

    The code hinting in VS is just heavenly. Just a hint ;)

  2. Simon says:

    I’m happy to see something new not related with Android :)

  3. reyco1 says:

    Ok, this is officially badass.

  4. Aaron says:

    Great tutorial. (Although, I would like to see more of the mouse cursor recorded in videos … :) ).

  5. Aaron says:

    Oh, and C# does have a typical “for” loop, where you could have done: for(int count=0; count < args.Length; count++) { …. }

    :)

  6. NAZ says:

    Great Lee, i was actually searching about NativeProcess and how to plug different languages last week.

    Great demo and could you tell how to do it but like not saving file but giving it back to flash and add it to stage?, it would be Kick ass!

  7. Bo says:

    Thanks, Lee – those are great!

    And I really appreciate the fact that you didn’t somehow edit out your name conflict at the end of the second tutorial. I’ve been there and it is not so obvious what might be the problem. Great to leave that in.

  8. Steve says:

    It is probably worth mentioning:

    If you know your “client” has the .NET framework version you require available then you should be fine with building out .NET native solutions that talk to an Adobe AIR application. Otherwise, for your application to work the “client” will need both the .NET Framework as well as the Adobe AIR platform installed and then your AIR App along with the C# utility app. This can make stuff pretty fun for debugging if you are new to .NET and what it might take to get a PC setup to run a .NET application.

    In a perfect world, Adobe AIR could launch a .NET installer that ensures the PC has all of the required elements of .NET in place before running the AIR app you’ve written. That would be pretty cool. You could package the distributable version of the .NET framework with your AIR Native installer and AIR could launch that EXE so those dependencies could be setup and then install your app and it would all work great.

    What happens now Lee if you attempt to install that app on a PC without (the correct version of) the .NET framework?

    BUT having said that, this is still a killer demo. I just didn’t want any newbies out there thinking they were going to build full blown .NET logic running under an AIR interface and it would all install as easily as an AIR application (unless I am missing something and it is?)

  9. K Manny says:

    Great tutorial Lee, I am fluent in 4 languages of programming and I couldnt help myself and created your demo using Objective C, for Mac and had no issues this is great stuff. Native support is key for better AIR apps.

  10. Lee Brimelow says:

    @Steve yes you are absolutely right, although what I built should run on all Vista and Win7 installations as far as I know. But your comments about having the .NET framework is definitely true. This would actually be pretty easy to build in C++ as well without using .NET.

  11. miguel says:

    thanks lee, i love these last two AIR 2.0 tutorials, awesome!

  12. Isaac says:

    @Steve, Nice point but I think the overall aim is to show how the nativeProcess works and could be any other platform. E.g This has taught me how to use the ffmpeg encoder with AIR and that’s a powerful combo :)

    @Lee, how can we implement same on an Android? Since we can’t compile AIR apps on an android based Flash IDE.

  13. jim says:

    I cannot run the application on the platform of linux or mac, isn’t it?

  14. Shawn says:

    @Isaac You can’t do this in Android right now, and it’s not planned for version 1.0. I’m sure it will be top on the list for the next version.

    There are some methods to bootstrap an air app, to a native apk, and then communicate with the native app, exposing additional API’s. It’s totally undocumented, and unsupported though.

  15. Nabeel says:

    Thanks Lee for that amazing two tutorials,
    I just has one question how could you export exe file from flash builder when I clicked on release build button I couldn’t find the executable installer section ?????

  16. personman says:

    This is unrelated to anything you’ve posted in the last few months, but I think you forgot Just Ask Us 3. Even though 90% of the questions aren’t relevant anymore.

  17. nabeels' friend says:

    @nabeel
    i’ve got the same problem here..
    anyone, do i need to update or install something?

  18. miguel says:

    love the new loook you got, but i liked the black “comments” thing better……

  19. fred says:

    Although I am not very sure, It seems that some code on the gotoandlearn.com site is being abused by someone to take advantage of the following leak:

    http://seclists.org/fulldisclosure/2010/Apr/119

    I recieved virus warnings when opening tutorial part1, and a java app was installed.

    today @14hr CET

    links:
    http://www.theregister.co.uk/2010/04/14/critical_java_vulnerability_exploited/

    apparently “npdeploytk.dll” is the cause (for installs older than 6.20)

    please check.

  20. miguel says:

    @nabeel and his friend

    First make sure your project is AIR 2, then go to File -> Publish Settings -> Adobe AIR 2 Settings
    In the General tab

  21. miguel says:

    @nabeel and his friend

    First make sure your project is AIR 2, then go to File -> Publish Settings -> Adobe AIR 2 Settings
    In the General tab, under “Output file”, check Windows installer (.exe), if your on PC, MAC should be similar.

    saludos

  22. Eric says:

    Really nice tutorial as always :)

    About part 2 in the mouse up event, maybe this example looks cleaner.
    Untested code, so it may not work right away.

    var args:Vector. = new Vector.();
    if(mouseX != sx || mouseY != sy)
    {
    args.push(“-l”);
    args.push(String( Math.min(mouseX, sx) )); //min X
    args.push(“-t”);
    args.push(String( Math.min(mouseY, sy) )); //min Y
    args.push(“-r”);
    args.push(String( Math.max(mouseX, sx) )); //max X
    args.push(“-b”);
    args.push(String( Math.max(mouseY, sy) )); //max Y
    }
    else
    {
    // height or width is going to end up 0, do something
    }

  23. nabeels' friend says:

    @miguel…

    thanks for your reply :)
    but, the question is how to do it inside of Flash Builder IDE, not Flash CS5 Professional?

  24. KolNedra says:

    Very nice.
    Also works excellent with CS5 pro.

    Only downside is that it doesn’t support multiple displays…

  25. KolNedra says:

    About my previous comment.
    if you have (for instance) a dual display setup, don’t use the FULL_SCREEN_INTERACTIVE displaystate, but simply
    set the nativeWindow’s position to 0,0 and resize the stage.stageWidth to (Capabilities.screenResolutionX * 2) and ofcourse the stage.stageHeight to Capabilities.screenResolutionY.
    Now you can make a mulitple display screenshot

  26. miguel says:

    @nabeel’s friend..
    i’m sorry.. is this what you’r looking for?
    http://www.adobe.com/devnet/air/flex/articles/air_screenrecording.html

    I haven’t tried it out yet, but if you do pls let us know how it went :)

  27. miguel says:

    [update] i think you only have to put “extendedDesktop” in the app.xml

  28. miguel says:

    <supportedProfiles>extendedDesktop</supportedProfiles>

  29. pip says:

    “AIR 2.0 Native Process” are great tutorials!! It’s so coooooooooool!!

    But I have a question about it. Would you please tell me how to use the “Generate Handler Method” function at 25:06 in the video.

    I’ ve tried for a long time, but I could not find it.

    Thanks for your help!!

  30. Raweden says:

    i would be much easier to use the sprite.getBounds() to send the args?

  31. Jake says:

    How would you call things native to windows like ftp via the command line… to use with NativeProcess.. Don’t import cmd.exe.
    Ya know in the command line you can do this:
    ftp http://ftp.mysite.com
    USER username
    PASS password1

Leave a Comment