AIR:- Desktop Application related to Window Component (Need some work around)
- by Mahesh Parate
Create custom component which contains Combobox and Datagrid.
Application conations two button 1) Same Window and 2) New Window.
(Label of two button)
When you click on “Same Window” button your custom component should
get added dynamically in your application.
And when you click on “New Window” button your custom component should
get open in different window (it should get shifted from application
and should appear in Window component).
Issue faced:-
Clicking on Combobox, list is not getting open as change event doesn’t
get fired in Native Window as it looses reference from main
application.
Issue with DataGrid in Native window (AIR).
• DataGridEvent.COLUMN_STRETCH event get affected if try to open
datagrid in Native Window.
• DataGridEvent get fired but takes long time or even stuck while
column stretch
Note:
Application is an Desktop Application.
Only one instance is created in Application for your custom component
to preserve current state on your custom component it can be Style,
data, or other subcomponent state of your custom component (as above
mentioned 2 component are just sample).
Please find sample code below:-
DataGridStretchIssue.mxml:-
<
?xml version="1.0" encoding="utf-8"?
<
mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute" xmlns:local="*" width="800" height="500"
<
mx:Script
<
![CDATA[
import mx.events.FlexEvent;
import mx.core.Window;
private var dgComp:DataGridComp = new DataGridComp();
private var win:Window;
private function clickHandler(event:Event):void{
dgComp.percentWidth = 100;
dgComp.percentHeight = 100;
dgComp.x = 50;
dgComp.y = 100;
if(win){
win.close();
}
this.addChild(dgComp);
}
private function openClickHandler(event:MouseEvent):void{
dgComp.x = 50;
dgComp.y = 100;
win = new Window();;
win.width = 800;
win.height = 500;
win.addChild(dgComp);
dgComp.percentWidth = 100;
dgComp.percentHeight = 100;
dgComp.x = 50;
dgComp.y = 100;
win.open(true)
}
]]>
<
/mx:Script
<
mx:HBox
<mx:Button id="btnID" click="clickHandler(event)" label="Same Window"/>
<mx:Button id="btnIDOpen" click="openClickHandler(event)" label="New Window"/>
<
/mx:HBox
<
/mx:WindowedApplication
DataGridComp.mxml
<
?xml version="1.0" encoding="utf-8"?
<
mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="100%"
height="100%"
<mx:Script>
<![CDATA[
import mx.events.DataGridEvent;
import mx.collections.ArrayCollection;
[Bindable]
public var cards:ArrayCollection = new ArrayCollection(
[ {label:"Visa", data:1},
{label:"MasterCard", data:2},
{label:"American Express", data:3} ]);
private function stretchFn(event:DataGridEvent):void{
trace("--- Stretched---")
}
]]>
</mx:Script>
<mx:HBox>
<mx:ComboBox dataProvider="{cards}" width="150"/>
<mx:DataGrid columnStretch="stretchFn(event)" >
<mx:ArrayCollection>
<mx:Object>
<mx:Artist>Pavement</mx:Artist>
<mx:Price>11.99</mx:Price>
<mx:Album>Slanted and Enchanted</mx:Album>
</mx:Object>
<mx:Object>
<mx:Artist>Pavement</mx:Artist>
<mx:Album>Brighten the Corners</mx:Album>
<mx:Price>11.99</mx:Price>
</mx:Object>
</mx:ArrayCollection>
</mx:DataGrid>
</mx:HBox>
<
/mx:Canvas
Can any one suggest me some work around to make my code workable... :)