josef.van.niekerk
josef.van.niekerk

Reputation: 12121

Pure AS3 Project with onInvoke working

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

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?

Upvotes: 0

Views: 2117

Answers (1)

Matt Beldyk
Matt Beldyk

Reputation: 121

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.

Upvotes: 3

Related Questions