Adobe AIR: Transferring parameters to a local executable program

Source: Internet
Author: User
Tags event listener printf

This article from: http://blog.everythingflex.com/2009/12/15/adobe-air-passing-arguments-into-native-executables/

I've discussed a section on the upcoming Flex 4 cookbook on air Basics for O ' Reilly, including about how to use local executable programs.

Here is an example of me:

First, I created a simple application that includes some local C code that takes only a few parameters and then outputs it to the screen. I compiled this C application into an executable program that can run on Mac, Windows, and Linux Ubuntu.

I then created an air application that includes the following code snippet. As shown below:

When I call the Callnativeapp () method, I identify a path to the Nativeapps directory that is packaged into my application. Then, depending on the operating system running the application, I specify the file variable to the appropriate executable program.

Next, I created the Nativeprocessstartupinfo object and set the executable properties. I also create a parameter vector and set it to the parameter properties of the Nativeprocessstartupinfo. It is then passed to ARGC, which is the variable of my executable.

Finally, I created an nativeprocess instance to add an event listener for Progressevent.standard_output_data. I started this process and closed the input.

The executable will simply consult the ARGC, invoke printf, and then trigger the progress event and alert in the air application.

Examples of ActionScript fragments:

private Var process:nativeprocess; Private Function Callnativeapp (): void{var file:file = file.applicationdirectory; file = File.resolvepath ("Nativeapps") ; if (Capabilities.os.toLowerCase (). IndexOf ("Win") >-1) {file = File.resolvepath ("Windows/sample.exe");} else if ( Capabilities.os.toLowerCase (). IndexOf ("Mac") >-1) {file = File.resolvepath ("Mac/sample");} else if ( Capabilities.os.toLowerCase (). IndexOf ("Linux") >-1) {file = File.resolvepath ("Linux/sample");} var Nativeprocessstartupinfo:nativeprocessstartupinfo = new Nativeprocessstartupinfo (); nativeprocessstartupinfo.executable = file; var args:vector.<string> = new vector.<string> (); Args.push ("Rich Trretola"); Args.push ("loves"); Args.push ("Flex & AIR"); nativeprocessstartupinfo.arguments = args; Process = new nativeprocess (); Process.addeventlistener (Progressevent.standard_output_data, onstandardoutputdata); Process.Start (Nativeprocessstartupinfo); Process.closeinput (); } Private Function OnstandarDoutputdata (event:progressevent): void{alert.show (Process.standardOutput.readUTFBytes ( process.standardOutput.bytesAvailable)); }

Sample code:

#include <stdio.h> int main (int argc, const char * argv[]) {if (argc > 1) {int i; for (i=1; i<argc; i++) {Prin TF ("/n"); printf (argv[i]); }} printf ("/n"); return 0; }

Here's the result:


It's enough to lift your appetite.

To get all the source code, you will have to wait for the book to be published.

Flash Builder 4 official version download address: http://g.csdn.net/5128184

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.