3 Replies Latest reply on Apr 24, 2009 12:10 PM by tzeng

    Need a tip for an image viewer

    HenryWalkerWalker Level 1

      Hi guys i'm trying to make an Image Viewer app and i couldn't find a way to tell my main AS3 class which is the Image that opened the application.

       

      I already specified images in windows to "Open with" my Image Viewer, and indeed my application executes but, is there a way to register the path of the file that opened my application?

       

      So far i've only seen drag&drop implementations, and i imagine that your answer will be a negative but i'm trying to find a solution to this because it's the only problem that keeps me from replacing the Windows Picture and Fax Viewer, so any tip, any idea, will be appreciated.

        • 1. Re: Need a tip for an image viewer
          Joe ... Ward Level 4

          The path to the file is placed in the arguments property of the InvokeEvent dispatched by the NativeApplication object when your application starts up.

          • 2. Re: Need a tip for an image viewer
            HenryWalkerWalker Level 1

            Thanks mate!

             

            It is now possible to do it with AIR 1.5.1

             

            In case someone needs it, here's the code that does the magic (AS3.0)

             

             

             

            import flash.display.NativeWindow;
            import flash.desktop.NativeApplication;


            import flash.events.InvokeEvent;

             

             

            var fileLoader:Loader = new Loader();
            addChild(fileLoader);

             

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

             

            function handleInitializationArgs(event:InvokeEvent):void
            {
                // get the application arguments from
                // the InvokeEvent object
               var args:Array = event.arguments as Array;
                       
                // if arguments were provided to the application
                if (args.length)
                {
                    // of the arguments provided, assume the first
                    // is of the associated file type
                    var fileToOpen:String = String(args[0]);
                    // load that argument as a url into the loader
                    fileLoader.load(new URLRequest(fileToOpen));
                }
            }

            • 3. Re: Need a tip for an image viewer
              tzeng Adobe Employee

              You can do this with all versions of AIR.

               

              -ted