views:

116

answers:

2

Hi, I'm developing an AIR application, where i need to access WindowedApplication's function from the package class.

This is the Main application (Partial code)

<mx:WindowedApplication  xmlns:mx="http://www.adobe.com/2006/mxml"
    layout="absolute" creationComplete="initApplication()">
<mx:Script>
    <![CDATA[

 import mx.events.CloseEvent;
 import messages.MessageWindow
public function undock():void {

        stage.nativeWindow.visible = true;
        stage.nativeWindow.orderToFront();

        //Clearing the bitmaps array also clears the applcation icon from the systray

        NativeApplication.nativeApplication .icon.bitmaps = [];
    }

  ]]>
</mx:Script>
</mx:WindowedApplication>

Package: (Partial code)


package messages
{
  public class MessageWindow extends NativeWindow
  {

    public function MessageWindow():void
    {

     stage.addEventListener(MouseEvent.MOUSE_DOWN,onClick);

    }
    private function onClick(event:MouseEvent):void
    {
        ****** Need to call the undock method from here. *****

    }
  }

}

Is it possible to call this way or suggest any other solution

Thanks in advance Senling.

+1  A: 

Cant see why it shouldnt work. Go ahead and give it a try, and if any errors come up, post it here.

What you can maybe try is to add parentApplication in front of stage in the MessageWindow method, like this..

parentApplication.stage.addEventListener(MouseEvent.MOUSE_DOWN,onClick);

and then call the undock() method from the onClick() method

Pieter van Niekerk
Hi, Thanks for your reply. I have tried this way and no error and nothing happened.'undock' method is located inside the WindowedApplication, i need to call this method from the package class(messages.MessageWindow), upto onclick method no issue, while calling the undock method, i'm facing the issue. Or is there any option to get reference to the main WindowedApplication. Thanks in advanceSenling.
Senling
have you tried adding parentApplication to the undock() method?
Pieter van Niekerk
No, I'm bit confused. please make it clearThank you
Senling
in the onClick() method, use parentApplication.undock() instead of just undock()
Pieter van Niekerk
Hi, pietervn, thanks for your fast response.I couldn't access the parentApplication property from message.MessageWindow. i also tried mx.core.UIComponent.parentApplication. I'm trying to dispatch event from message.MessageWindow class to main WindowedApplication which listens that event to call the undock method., but it failed.
Senling
+1  A: 

Even if I don't recommend this for the sake of your code design, you can access your method like this: Application.application.undock() (if your undock() method is public in the WindowedApplication )

flexwizz