Creating custom windows with Adobe AIR

Adobe AIR allows you to customize the windows of their applications, by default, Adobe AIR uses the layout of the windows operating system (Windows, Mac, Linux), in Flex you have the option of using FlexChrome(especially that i am not very fan).
Show a simple example using Adobe Flex, Adobe Dreamweaver CS4 and Adobe Flash CS4.

if you’re new to Adobe AIR, i recommend you look this article before proceeding with the tutorial 😉


Adobe Flex

In Flex Builder, create a project of type “Desktop application”, by default it will create two files, one .mxml and one .xml responsible for the application settings.
The .xml file, change the follwing tags: systemChrome e transparent.
The final file should be as follows::
[xml]
< ?xml version="1.0" encoding="UTF-8"?>

AIR-chrome
AIR_chrome
AIR_chrome
v1

[This value will be overwritten by Flex Builder in the output app.xml]
none
true


[/xml]
We configure our application to not use the Windows style operating system which is transparent. If run the application, we see that window appears pattern Flex (FlexChrome). However it is not what we want yet.
In the file .mxml, in WindowedApplication tag, we set the showFlexChrome property to false.
[mxml]


[/mxml]
If we run again, we see that standard window of Flex also disappeared. Now create the rest of the application.
Add a component Canvas, size of your choice, and add three components of type “Button” on stage, important to remember to put a background color of Canvas for your application to be seen.
[mxml]
< mx :Canvas id="cv_back" width="100%" height="100%" cornerRadius="10" borderStyle="solid" backgroundColor="#061D7E">



< / mx:Canvas>
[/mxml]

Now let’s add the actions to minimize, maximize, restore and close the application. For this we have access to own API for Adobe AIR windows. Note that to mazimize and restore, we use a flag to see if the window is maximized or not.
[actionscript3]
private var isMax:Boolean = false;

private function minimizar(e:MouseEvent):void
{
stage.nativeWindow.minimize();
}

private function maximizar(e:MouseEvent):void
{
if(!isMax)
{
stage.nativeWindow.maximize();
isMax = true;
}
else
{
stage.nativeWindow.restore();
isMax = false;
}
}

private function fechar(e:MouseEvent):void
{
stage.nativeWindow.close();
}
[/actionscript3]
Now to complete a task for which the window can ve dragged witn the mouse.
[actionscript3]
private function moveit(e:MouseEvent):void
{
stage.nativeWindow.startMove();
cv_back.alpha = 0.5;
}
[/actionscript3]
Then just add a function that will make the buttons “listening” these functions. Following is the complete code:
[mxml]
< ?xml version="1.0" encoding="utf-8"?>
< mx :WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" showFlexChrome="false" creationComplete="init();">
< mx :Script>
< ![CDATA[ private var isMax:Boolean = false; public function init():void { cv_back.addEventListener(MouseEvent.MOUSE_DOWN, moveit); cv_back.addEventListener(MouseEvent.MOUSE_UP, nomove); bot_min.addEventListener(MouseEvent.CLICK, minimizar); bot_max.addEventListener(MouseEvent.CLICK, maximizar); bot_close.addEventListener(MouseEvent.CLICK, fechar); } private function moveit(e:MouseEvent):void { stage.nativeWindow.startMove(); cv_back.alpha = 0.5; } private function nomove(e:MouseEvent):void { cv_back.alpha = 1; } private function minimizar(e:MouseEvent):void { stage.nativeWindow.minimize(); } private function maximizar(e:MouseEvent):void { if(!isMax) { stage.nativeWindow.maximize(); isMax = true; } else { stage.nativeWindow.restore(); isMax = false; } } private function fechar(e:MouseEvent):void { stage.nativeWindow.close(); } ]]>
< / mx:Script>
< mx:Canvas id="cv_back" width="100%" height="100%" cornerRadius="10" borderStyle="solid" backgroundColor="#061D7E">



< / mx:Canvas>
< / mx:WindowedApplication>
[/mxml]

Download dos arquivos

Adobe Flash CS4 or CS3

To create application in Adobe AIR with Adobe Flash CS3, you need to upgrade. Visit Adobe AIR Update for Flash CS3 Professional. Adobe Flash CS4 comes with native support for building applications on Adobe AIR.

Create a new file type “Flash File(Adobe AIR)” and add three components of the type “Button” on stage. They are respectively the buttons to minimize, maximize, restore and close. The first time you compile the FLA, it create one file .xml of your application. To configure it, just go to File->AIR Settings…
Edit the information to your preferences, do not forget to check the option Window Chrome as “Custom Chrome(transparent)”, its configuration file should look something like the following:
[xml]
< ?xml version="1.0" encoding="UTF-8" standalone="no" ?>

com.adobe.example.chrome
1.0
chrome

chrome


chrome.swf
none
true true
true
true
true


false
false

[/xml]
I created a movieclip blue with the name of instance “mc_chrome” to be a background application.
Now putting the actions on the buttons to be placed in the main timeline:
[actionscript3]
var isMax:Boolean = false;

mc_chrome.addEventListener(MouseEvent.MOUSE_DOWN,moveit);
mc_chrome.addEventListener(MouseEvent.MOUSE_UP,nomove);

function moveit(e:MouseEvent):void
{
stage.nativeWindow.startMove();
mc_chrome.alpha = .5;
//mc_chrome.blur
}

function nomove(e:MouseEvent):void
{
mc_chrome.alpha = 1;
}

////////
bot_min.addEventListener(MouseEvent.CLICK,minimizar);
function minimizar(e:MouseEvent):void
{
stage.nativeWindow.minimize();
}
bot_max.addEventListener(MouseEvent.CLICK,maximizar);
function maximizar(e:MouseEvent):void
{
if (!isMax)
{
stage.nativeWindow.maximize();
isMax = true;
}
else
{
stage.nativeWindow.restore();
isMax = false;
}
}
bot_close.addEventListener(MouseEvent.CLICK,fechar);

function fechar(e:MouseEvent):void
{
stage.nativeWindow.close();
}
[/actionscript3]

Download dos arquivos

Adobe Dreamweaver CS4 or CS3

To use the Adobe AIR with HTML/Ajax, i will use Adobe Dreamweaver CS3, but nothing prevents you from using your editor and compile using the Adobe AIR SDK.
With Dreamweaver is possible to have access to API code hints specifies Adobe AIR for JavaScript, simply install the folowing extensions:
Adobe AIR Extension for Dreamweaver

In the item “Site” Dreamweaver will appear two new options (Create AIR File and AIR Application Settings). Create a new HTML document and the Files windows, next to Site->AIR Application Settings. Complete the required information, you will have create one file .xml with the settings of your application, its content should be as below:
[xml]
< ?xml version="1.0" encoding="utf-8" ?>

air
false
airteste
air
1

air.html
600
800
none
true true


[/xml]
We changed the systemChrome for “none” and transparent for “true”, the rest is your choice.
Add three buttons in html to be respectively the buttons to minimize, maximize, restore and close:
[html]



[/html]
Now we will create the functions that perform these actions. we note that by accessing the API specifies the Adobe AIR for JavaScript.
[javascript]

[/javascript]
The logic follows the same that we use in Flex and Flash, a flag for whether the window is maximized or not.
Then we set the buttons to perform the various functions. Following is the complete code:
[html]
< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">



teste







[/html]
Download dos arquivos

Create a custom window give a greate freedom for you to create the application with the “face” of the user, is a powerful resource and therefore it should be used with create care, no use having a layout hyper super ultra mega power futuristic and compromisse the usability user.

Recommend:
http://www.adobe.com/devnet/air/

Recommended Books:


Translations:
Português do Brasil

Was this article helpful? feel free to make a donation and help keep the blog in the air
ActionScript 3.0, Adobe AIR, Flash, Flex , , ,

1 comment


Leave a Reply