Skip to content
Mar 12 /

Opening a new Window in Adobe AIR

The following example shows how you can launch a new Flex Window container in Adobe AIR by creating a custom Window component and calling the open() method.

<?xml version="1.0" encoding="utf-8"?>
<!-- http://airexamples.com/2010/03/12/opening-a-new-window-in-adobe-air/ -->
<mx:WindowedApplication name="Window_open_test"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">
 
    <mx:Script>
        <![CDATA[
            import mx.core.Window;
 
            protected function btn_clickHandler(evt:MouseEvent):void {
                new MyWin().open();
            }
        ]]>
    </mx:Script>
 
    <mx:Button id="btn"
            label="Open Window"
            click="btn_clickHandler(event);" />
 
</mx:WindowedApplication>

And the custom Window component, MyWin.mxml, is as follows:

<?xml version="1.0" encoding="utf-8"?>
<!-- http://airexamples.com/2010/03/12/opening-a-new-window-in-adobe-air/ -->
<mx:Window name="MyWin"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="absolute"
        width="300" height="200">
 
    <mx:Label id="lbl"
            text="I'm a Window!"
            fontSize="32"
            horizontalCenter="0" verticalCenter="0" />
 
</mx:Window>

8 Comments

leave a comment
  1. Bhaskar / Mar 24 2010

    Why you are still using halo components? you can use spark right?

  2. Tahir Alvi / Jul 29 2010

    Hi,
    I want to know that what is method to make a costume title bar in flash builder 4?

    Thanks

  3. feresr / Aug 13 2010

    Hi! i’m sorry. but can’t get this working.. i don’t know what i’m doing wrong..

    this is the error:

    access to an undifined proprety MyWin

    could you tell me what i’m doing wrong?

    thanks…

    • Peter deHaan / Aug 13 2010

      @feresr,

      Did you copy the second block of code and save it as MyWin.mxml in the same directory as the first code block?

      Peter

  4. feresr / Aug 13 2010

    oh!.. i did copy the second block.. but i didn’t name it as MyWin.mxml.. that may be the Error..

    Thank you for answering me. !.

  5. feresr / Aug 14 2010

    Hi again, I’m sorry but i still have some problems with this code… and i think it’s because of my windows’ code.. it doesn’t look like yours.

    This is what i mean:
    Your code:

    My code:

    As you can see, the only difference is that little ‘s:’ at the begining of my code. I can’t change it because my whole windows has components.

    Flex created these tags. And i don’t know why…

    This is the Error i’m getting now: ‘Call to an undefined method open’.

    I hope you know the aswer :) and i’m apologize for my english. I’ts not my native language.

    Ow! and by the way.. could you tell me what’s the name of the font you have in the header of the web site (‘A bunch of Adobe Air…’).

    Thank you! And congratulations for the website.

  6. Feresr / Aug 15 2010

    I discovered what i was doing wrong… This example was really useful. Thanks. Bye

Leave a Comment

Spam Protection by WP-SpamFree