2 Replies Latest reply on Oct 2, 2012 8:11 AM by trustmeiamacoder

    air nativemenuItem and systemtray problem

    trustmeiamacoder

      package {

       

       

                import flash.display.MovieClip;

                import flash.display.*;

                import flash.events.*;

                import flash.ui.*;

                import flash.net.*;

                import flash.desktop.*;

                import fl.controls.DataGrid;

                import fl.controls.dataGridClasses.*;

                import flash.utils.Timer;

       

       

                public class kuyumcu extends MovieClip {

                          var id:Number=0;

                          //contek menu ayarları

                          public var my_menu:ContextMenu = new ContextMenu();

                          public var my_company:ContextMenuItem=new ContextMenuItem("Rize Kuyumcular Derneği - 2012");

       

       

                          //program giriş nesneleri

                          public var giris:login;

                          public var ekranMc:ekran;

                          var girisdemisin:Boolean=false;

                          var ekrandamisin:Boolean=false;

                          var mesajAcikmi:Boolean=false;

       

       

                          var loader:Loader = new Loader();

       

       

                          var mesajkontrolurl:URLRequest=new URLRequest("http://www.rikud.org/sql/mesajvarmi.php");

                          var mesajkontrolloader:URLLoader=new URLLoader();

                          var mesajkontrolvars:URLVariables = new URLVariables();

       

       

                          var sayac:Timer=new Timer(30000,0);

       

       

                private var gosterTrayButonu:NativeMenuItem=new NativeMenuItem("Göster");

                          private var gizleTrayButonu:NativeMenuItem=new NativeMenuItem("Gizle");

                          private var mesajlarTrayButonu:NativeMenuItem=new NativeMenuItem("Mesajlar");

                          private var kapatTrayButonu:NativeMenuItem=new NativeMenuItem("Programı Kapat");

       

       

                var trayMenu:NativeMenu = new NativeMenu();

       

       

       

       

       

       

                          public function kuyumcu () {

                                    addEventListener ( Event.ADDED_TO_STAGE, sahnede, false, 0, true );

                          }

       

       

                          function sahnede (e:Event) {

                                    my_menu.hideBuiltInItems ();

                                    my_company.addEventListener (ContextMenuEvent.MENU_ITEM_SELECT, openLink);

                                    my_menu.customItems.push (my_company);

                                    contextMenu=my_menu;

       

       

       

       

                                    stage.scaleMode="noScale";

                                    stage.align="top_left";

       

       

                                    stage.addEventListener (Event.RESIZE, onSizeChange);

                                    giris=new login(stage.stageWidth,stage.stageHeight);

                                    giris.addEventListener ("girisOK", loginOK);

                                    girisdemisin=true;

                                    addChild (giris);

                          }

       

       

                          function loginOK (e:loginEvent) {

                                    sayac.addEventListener (TimerEvent.TIMER, sayacAt);

                                    sayac.start ();

       

       

                                    id=Number(e.kullaniciID);

       

       

                                    mesajkontrolurl.method=URLRequestMethod.POST;

                                    mesajkontrolvars.id=id;

                                    mesajkontrolurl.data=mesajkontrolvars;

                                    mesajkontrolloader.addEventListener (Event.COMPLETE, mesajKontrol);

                                    mesajkontrolloader.load (mesajkontrolurl);

       

       

                                    girisdemisin=false;

       

       

                                    ekranMc=new ekran(id);

                                    addChild (ekranMc);

                                    //stage.displayState=StageDisplayState.FULL_SCREEN_INTERACTIVE;

                                    removeChild (giris);

                                    ekranMc.konumlandir ();

                                    ekrandamisin=true;

                                    //trayaAt ();

                          }

       

       

                          function sayacAt (e:TimerEvent):void {

                                    if (! mesajAcikmi) {

                                              mesajkontrolurl.method=URLRequestMethod.POST;

                                              mesajkontrolvars.id=id;

                                              mesajkontrolurl.data=mesajkontrolvars;

                                              mesajkontrolloader.addEventListener (Event.COMPLETE, mesajKontrol);

                                              mesajkontrolloader.load (mesajkontrolurl);

                                    }

                          }

       

       

                          function mesajKontrol (e:Event):void {

                                    if (e.target.data=="mesajvar½0") {

       

       

                                    } else if (e.target.data == "mesajvar½1") {

                                              createNativeWindow ();

                                    }

                          }

       

       

                          function phpGeldi (e:Event) {

                                    trace (e.target.data);

                          }

       

                          public function onSizeChange (e:Event) {

                                    if (girisdemisin) {

                                              giris.konumlandir ();

                                    }

                                    if (ekrandamisin) {

                                              ekranMc.konumlandir ();

                                    }

                          }

       

       

                          public function openLink (e:ContextMenuEvent):void {

                                    navigateToURL (new URLRequest("http://www.*****.org"));

                          }

       

                          function trayaAt () {

                                    //pencere ayarları

                                    var simgeWin:String="/icons/16x16.png";

                                    var simgeMac:String="/icons/128x128.png";

                                    var simgeYukleyici:Loader = new Loader();

       

       

                    trayMenu.addItem (gosterTrayButonu);

                    trayMenu.addItem (gizleTrayButonu);

                    trayMenu.addItem (mesajlarTrayButonu);

                    trayMenu.addItem (kapatTrayButonu);

       

       

                                    if (NativeApplication.supportsSystemTrayIcon) {

                                              NativeApplication.nativeApplication.autoExit=false;

                                              simgeYukleyici.contentLoaderInfo.addEventListener (Event.COMPLETE, simgeYuklendi);

                                              simgeYukleyici.load (new URLRequest(simgeWin));

                                    }

       

       

                                    if (NativeApplication.supportsDockIcon) {

                                              simgeYukleyici.contentLoaderInfo.addEventListener (Event.COMPLETE,simgeYuklendi);

                                              simgeYukleyici.load (new URLRequest(simgeMac));

                                    }

       

       

       

       

                    gosterTrayButonu.addEventListener (Event.SELECT, btnGoster);

                    gizleTrayButonu.addEventListener (Event.SELECT, btnGizle);

                    mesajlarTrayButonu.addEventListener (Event.SELECT, btnMesaj);

                    kapatTrayButonu.addEventListener (Event.SELECT, btnKapat);

                          }

       

       

       

       

                          function simgeYuklendi (event:Event):void {

                                    if (NativeApplication.supportsSystemTrayIcon) {

                                              var traySimge:SystemTrayIcon=NativeApplication.nativeApplication.icon as SystemTrayIcon;

                                              traySimge.menu=trayMenu;

                                    }

       

       

                                    if (NativeApplication.supportsDockIcon) {

                                              var macDock:DockIcon=NativeApplication.nativeApplication.icon as DockIcon;

                                              macDock.menu=trayMenu;

                                    }

                                    NativeApplication.nativeApplication.icon.bitmaps=[event.target.content.bit mapData];

                          }

       

       

                          function btnGoster (event:Event) {

                                    stage.nativeWindow.activate ();

                                    stage.nativeWindow.visible=true;

                          }

       

       

                          function btnGizle (event:Event) {             

                                    stage.nativeWindow.visible=false;

                          }

       

       

                          function btnMesaj (event:Event) {

                                    if (! mesajAcikmi) {

                                              createNativeWindow ();

                                              mesajAcikmi=true;

                                    }

                          }

       

       

                          function btnKapat (event:Event) {

                                    NativeApplication.nativeApplication.icon.bitmaps=[];

                                    NativeApplication.nativeApplication.exit ();

                          }

       

       

                          public function createNativeWindow ():void {

                                    var mesaj:URLRequest=new URLRequest("/mesaj.swf");

                                    loader.contentLoaderInfo.addEventListener (Event.COMPLETE, mesajGeldi);

                                    loader.load (mesaj);

       

       

                                    //create the init options

                                    var options:NativeWindowInitOptions = new NativeWindowInitOptions();

                                    options.transparent=false;

                                    options.systemChrome=NativeWindowSystemChrome.STANDARD;

                                    options.type=NativeWindowType.NORMAL;

       

       

                                    //create the window

                                    var newWindow:NativeWindow=new NativeWindow(options);

                                    newWindow.title="Kuyumcu Ekranı - Mesaj";

                                    newWindow.width=600;

                                    newWindow.height=400;

       

       

                                    newWindow.stage.align=StageAlign.TOP_LEFT;

                                    newWindow.stage.scaleMode=StageScaleMode.NO_SCALE;

       

       

                                    //activate and show the new window

                                    mesajAcikmi=true;

                                    newWindow.activate ();

                                    newWindow.addEventListener (Event.CLOSE, onClose);

                                    newWindow.stage.addChild (loader);

                          }

       

       

                          function mesajGeldi (e:Event):void {

                                    MovieClip(loader.content).mesajlarBaslat (Number(id));

                          }

       

       

                          function onClose (e:Event) {

                                    mesajAcikmi=false;

                                    trace ("kapandı");

                          }

       

       

                }

      }

       

       

      ok here is my problem. when i run this program using flash player everything is normal and great. ven i run it on a projector there is a problem about NativeMenuItems. when i disable nativemenuitem lines on code air runs good but this time i dont have a try icon and a menu.

       

      using air 2.6 and flash professional cs 5.5

        • 1. Re: air nativemenuItem and systemtray problem
          adobe_paul Adobe Employee

          You say the problem is happening when you run it "on a projector." It would help if you could clarify what that means. Is the problem when you're running it in the standalone Flash Player? (That's usually what "in a projector" means.) Or are you running it as an AIR application, either using ADL (i.e. directly from Flash Pro) or as a published/installed app?

           

          It's also confusing that you say it's working when you run it using Flash Player. Since Flash Player is a browser plugin, it doesn't support the AIR features you're talking about like NativeMenu, system tray icon, etc.

          • 2. Re: air nativemenuItem and systemtray problem
            trustmeiamacoder Level 1

            the problem is when I try to preview my app by using apple+Enter it works fine. but if i publish it using flash puplish settings and select from there mac projector it isnt working. but when i compile my app usin air settings and puplish it using air publisher. and install the application using by air and puff there is no problem every thing works fine.

             

            only problem was me (trying app wrong place). thanks

             

            note: this is my first air app try by the way