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:

LoaderInfo(this.root.loaderInfo).parameters
LoaderInfo(this.root.loaderInfo).parameters

In Flex applications:

Application.application.parameters
Application.application.parameters

In AS3 Air applications you can retrieve the passed in params via an InvokeEvent listener:

NativeApplication.nativeApplication.addEventListener
               (InvokeEvent.INVOKE, onInvokeEvent);
NativeApplication.nativeApplication.addEventListener
               (InvokeEvent.INVOKE, onInvokeEvent);

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:

  1. Multiple parameters:
    adl InvokeExample-app.xml ./ -- hello world
    adl InvokeExample-app.xml ./ -- hello world

    Screen shot 2011 07 03 at 13.55.01 How to pass in parameters to a Flex Air app at startup

  2. Multiple multi-word parameters:
    adl InvokeExample-app.xml ./ -- "green eggs" "and ham"
    adl InvokeExample-app.xml ./ -- "green eggs" "and ham"

    Screen shot 2011 07 03 at 13.57.05 How to pass in parameters to a Flex Air app at startup

  3. Speechmarks – simply escape them out:
    adl InvokeExample-app.xml ./ -- "\"green\" eggs" "and ham"
    adl InvokeExample-app.xml ./ -- "\"green\" eggs" "and ham"

    Screen shot 2011 07 03 at 17.28.24 How to pass in parameters to a Flex Air app at startup

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.

  1. Add your file extension in your application descriptor xml:
    <fileTypes>
       <fileType>
         <name>InvokeExample</name>
         <extension>meow</extension>
         <contentType>text/xml</contentType>
       </fileType>
     </fileTypes>
    <fileTypes>
       <fileType>
         <name>InvokeExample</name>
         <extension>meow</extension>
         <contentType>text/xml</contentType>
       </fileType>
     </fileTypes>
  2. Publish & install your app.
  3. Create a test file and double click on it:
    Screen shot 2011 07 03 at 17.38.03 How to pass in parameters to a Flex Air app at startup
    Screen shot 2011 07 03 at 17.38.19 How to pass in parameters to a Flex Air app at startup
Tagged with:
 

Leave a Reply

Your email address will not be published. Required fields are marked *

*


eight − = 0

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code lang=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" extra="">