> I've got something like
> creationCompleteHandler:
>               var sysTrayIcon:SystemTrayIcon =
>                       NativeApplication.nativeApplication.icon as 
> SystemTrayIcon;
>                   sysTrayIcon.addEventListener(MouseEvent.CLICK,undock);    
> 
> undock:
>               if (!stage.nativeWindow.visible){
>                       stage.nativeWindow.visible = true;
>                       stage.nativeWindow.activate();
>               
>               }else{
>                       stage.nativeWindow.visible=false;                       
>               }
> and it works here to show/hide the main application window.
> 
> Where are you assigning the event handler, and why are you using the
funny 
> inline function syntax ? 
> If you stop it in the debugger, what is the bit that is actually null ?
> 
> -- 
> Tom Chiverton

Thank Tom very much. In my country, few days ago is Lunar new year so
I don't work and reply :( 
Your solution is very good if the event handler in MXML file. I
correct my code follow you and have good result.
But I have only special case, the event handler in AS class

My code in main.mxml 

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication
  <mx:Script>
  ...
  </mx:Script>

<!--Call AS class -->
  <com:SysTrayApp>
                
  </com:SysTrayApp>
</mx:WindowedApplication>

and code in systrayapp.as file

package com
{
  import flash.desktop.DockIcon;
  import flash.desktop.NativeApplication;
  import flash.desktop.SystemTrayIcon;
  import flash.display.Loader;
  ....
public class SysTrayApp extends Sprite
  {
  public function SysTrayApp():void{
    NativeApplication.nativeApplication.autoExit = false;
    var icon:Loader = new Loader();
    var iconMenu:NativeMenu = new NativeMenu();
    var showCommand:NativeMenuItem = iconMenu.addItem(new
NativeMenuItem("Show"));                                                
    showCommand.addEventListener(Event.SELECT,
function(event:Event):void {
   
NativeApplication.nativeApplication.activeWindow.stage.nativeWindow.visible
= true;                         
                        });
............
}

So the error display when I click "show" menuitem in taskbar
TypeError: Error #1009: Cannot access a property or method of a null
object reference.

In debug mode the error at line
"NativeApplication.nativeApplication.activeWindow.stage.nativeWindow.visible
= true; "

how to solve it?

Reply via email to