AIR Tip 5: This tutorial will walk you through the process of passing arguments to an AIR application when it is installed using the AIR installer badge. It includes both an article as well as a demonstration video. This tutorial is current for Adobe AIR Beta 3.
Someone left a comment today asking if it was possible to send arguments to an application when it is installed via the AIR Installer Badge. The answer: yes and no. First, it cannot be done through the default badge that comes with the SDK. However, the badge can easily be modified to perform this. Second, for an AIR application to receive the BrowserInvokeEvent [Reference], the allowBrowserInvocation property in the application descriptor file must be set to true.
Modifying the AIR Install Badge
Assuming this is true, you should go ahead and create a modified AIR Install Badge. The source code for the badge comes with the Adobe AIR Beta 3 SDK. It can be found in the src/badge folder. You will need to edit the AIRBadge.as file in three places.
Code Example 1 - Creating the _arguments Property
Code Example 2 - Populating the _arguments Property with an Array of Arguments
Code Example 3 - Passing the _arguments Array to the AIR Installer
With these changes, you can now pass an arguments parameter into the badge installer, and it will pass those arguments to your AIR application on installation. As an example of this, I have created an AIR application that will display all of the arguments passed to it as a list. It also displays the other properties of the BrowserInvokeEvent.
For the installation, I modified my InstallBadge.js file to also include a property for the arguments (and also to pass those arguments in with the flashvars). For this example I have created a ColdFusion file which passed the IP Address and Server Name into the application as arguments.
The sample AIR application lists all properties of the BrowserInvokeEvent as well as a list of all of the arguments passed into it. You can see an example below (with the IP address and Server Name blurred).
Inserting the Modified Badge into a Site
I recently wrote an article for the Adobe AIR Develop Center entitled Deploying Adobe AIR applications seamlessly with the badge install feature. This article covers the entire process of inserting the badge onto a page. I have only modified these files slightly for this example (to add the arguments feature).
First, I have modified the InstallBadge.js file, and I have included the new version with the exercise file for this tutorial. Second, I added a new global variable (airApplicationArguments) to the head of the HTML page. This is a comma delimited list of arguments to pass to
Code Example 3 - Additional Global JavaScript Variable
Setting Up Your AIR Application
There are two settings that need to be considered when setting up your AIR application to receive BrowserInvokeEvents. First, you will need to modify your application descriptor file to allow your application to receive these events. Be sure that the allowBrowserInvocation option in your application descriptor file is set to true.
Code Example 4 - Allowing Browser Invocation for an AIR Application
Second, you will tell your application to listen for these events. This should be added as follows:
Code Example 4 - Adding Event Listener for BrowserInvokeEvents
Sample Application
The sample AIR application for this tutorial (as seen in the video) is available. It displays all of the information sent to it in a BrowserInvokeEvent. This application also has "View Source" enabled, so you can right-click it and view the actual code.
Video (Click to View)
Exercise Files
Install AIR Application - Click Here
Exercise Files (636 kb)
Reference
Livedocs - BrowserInvokeEvent
Developer Center - Deploying Adobe AIR applications seamlessly with the badge install feature
Developer Guide - Launching an Installed AIR Application from the Browser
[...] AIR Tip 5: Passing Arguments to an Application on Install (AIR 1.0) [...]
[...] Browser API that has been covered in AIR Tip 5 and AIR Tip 6 allows you not only to launch an AIR application from the browser, but also from [...]
[...] 来源:AIR Tip 5: Passing Arguments to an Application on Install [...]
I hit a bottleneck when using the flashvars arguments parameter to pass ip address from javascript.
As per the docs , to send arguments to the swf file , one can use the arguments parameter of the flashvars variable. If there any special characters as part of the variable value % and hexadecimal value should be used.
I have to pass for example the the following two values are parameters
172.1.12.25:8080/test1
172.1.13.26:8080/test2
I have created the argument values as
var airApplicationArguments = “172 %2E 12 %2E 25%3A 8080%2F abc,
172 %2E 13 %2E 26%3A 8080%2F efd&
“;
I get a invalid argument error.
Iam not sure what could be issue .Can u point me to the right direction. How did create the value for arguments variable ?
Where there any encoding involved ?
@randy – Since the Browser API is used to send the arguments – the Browser API determines what values are acceptable arguments. With AIR 1.0 the browser API changed a bit – and it only allows alpha-numeric values (no symbols). I haven’t had a chance to update this tutorial yet.
Yes you are right. Iam apprehensive about the Browser API , since it breaks the application from working , when it does changes like the alpha-numerics only. The best example is your tutorial , which is failing because of the changes .
Hello david,
Does this feature work if i click “save” instead of “install” ???
Anyways, thanks for all your tips.
@Remi – I don’t believe that it would, but I haven’t tested it.
So, this feature will be useless…
I’ve to try. ^-^
Do you know if there is a similar approach that can be utilized with sidecar installations on CD/DVD?
“Does this feature work if i click “save” instead of “install” ???”
If it doesn’t is there a way to simply remove the option to “save” the document and only allow for it to be directly installed?
IS it possible for having an input box at install time which will take one time input parameters and store them in the application.
The type of application will be normal AIR application without the Browser invoke event.