How to pass in parameters to a Flex Air app at startup
Air applications ((extended)desktop, (extended)mobileDevice, (extended)TV ) can accept custom startup parameters.
To retrieve passed in parameters in a web based pure AS3 applications, you need to use:
In Flex applications:
In AS3 Air applications you can retrieve the passed in params via an InvokeEvent listener:
In Flex Air application you need to listen to InvokeEvent.INVOKE
Flex 4 Parameter example
<?xml version="1.0" encoding="utf-8"?> <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" width="200" height="200"> <fx:Declarations> <s:ArrayCollection id="airParams" /> </fx:Declarations> <s:invoke> <![CDATA[ var invocation:InvokeEvent = InvokeEvent(event); for each(var argument:String in invocation.arguments) airParams.addItem(argument); ]]> </s:invoke> <s:List dataProvider="{airParams}" width="100%" height="100%" /> </s:WindowedApplication>
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
width="200" height="200">
<fx:Declarations>
<s:ArrayCollection id="airParams" />
</fx:Declarations>
<s:invoke>
<![CDATA[
var invocation:InvokeEvent = InvokeEvent(event);
for each(var argument:String in invocation.arguments)
airParams.addItem(argument);
]]>
</s:invoke>
<s:List dataProvider="{airParams}"
width="100%" height="100%" />
</s:WindowedApplication>
Test it from the command line:
- Multiple parameters:
- Multiple multi-word parameters:
adl InvokeExample-app.xml ./ -- "green eggs" "and ham"
adl InvokeExample-app.xml ./ -- "green eggs" "and ham"
- Speechmarks – simply escape them out:
adl InvokeExample-app.xml ./ -- "\"green\" eggs" "and ham"
adl InvokeExample-app.xml ./ -- "\"green\" eggs" "and ham"
Test it with custom file extension
You can register custom file extensions with your air app. When you open a file with a registered extension, the OS will open your air app and pass in the full path of the file as a parameter.
Blogroll






