views:

258

answers:

1

I'm trying to create a pure ActionScript 3 AIR project, without Flex, somewhat like in the following question:

http://stackoverflow.com/questions/966180/actionscript-project-to-air-application

...but I'm not really sure how to access command line arguments from onInvoke(). I need this for accessing command line arguments for my Pure AS3 AIR application.

Here's my source code:

public class Doclet extends Sprite
{
 public function Doclet()
 {
  NativeApplication.nativeApplication.addEventListener(InvokeEvent.INVOKE, onInvoke);

  var win:NativeWindow = new NativeWindow(new NativeWindowInitOptions());
  win.activate();
  win.addEventListener(Event.CLOSE, function():void
  {
   NativeApplication.nativeApplication.exit(0);
  });

  win.stage.addChild(this);

  stage.scaleMode = StageScaleMode.NO_SCALE;
  stage.align = StageAlign.TOP_LEFT;
 }

 private function onInvoke(event:InvokeEvent):void
 {
  trace('Invoke...');
 }
}

Imports omitted for brevity. Can anyone help?

+1  A: 

Here's an example from my code about how to do this:

//in my mxml WindowedApplication description:

<mx:WindowedApplication
    backgroundColor="0xFFFFFF"
    backgroundGradientColors="[0xFFFFFF, 0x93BBFF]"
    backgroundGradientAlphas="[0.5, 1]"
    xmlns:mx="http://www.adobe.com/2006/mxml"
    layout="absolute"
    initialize="initEvent(event)"
    >

//code that needs to go inside the script area of the mxml for this application

//                   initialization
private function initEvent(event:Event):void{
                NativeApplication.nativeApplication.addEventListener(InvokeEvent.INVOKE, onInvokeEvent);
                NativeApplication.nativeApplication.addEventListener(BrowserInvokeEvent.BROWSER_INVOKE,onBrowserInvoke);
            //  Alert.show(NativeApplication.nativeApplication.publisherID);
            }

//Ran when program is invoked (can run more than once)

        private function onInvokeEvent(event:InvokeEvent):void{
            trace("in onInvoke function");

            ++invokeCounter;


            if(event.arguments.length != 0){
                args = event.arguments.join(",");
            }else{//do nothing
            }
            firstInvoke = false;

        }

Also see adobe help for a more full description.

Matt Beldyk
Just added some source code, please keep in mind, I don't have a MXML file, my AIR app is starting up from Doclet.as :)
Joe Zephyr
Just got it to work, I dunno what was out of place...but:NativeApplication.nativeApplication.addEventListener(InvokeEvent.INVOKE, onInvokeEvent);solved my issue. Thanks for the help!!!
Joe Zephyr
no prob, I recall struggling with reading arguments from a browser invocation. It looks like the documentation is much more mature now (either that or I understand it better)
Matt Beldyk