Flex 3 DataGrid Component Losing Focus - actionscript-3

I'm running into problems getting the focus to work on my custom datagrid. It is a subclass of MDataGrid which can be found here.
My problems is, that every other mouse click on inline components actually focuses on the component. The other clicks seem to automatically lose focus to something else, and I can't seem to figure out what is going on. Any help would be greatly appreciated.
Thanks for your time.
--Charly
<?xml version="1.0" encoding="utf-8"?>
<controls:MDataGrid xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:controls="com.iwobanas.controls.*"
xmlns:dgc="com.iwobanas.controls.dataGridClasses.*"
dataProvider="{locator.vendorInvoices}"
editable="true">
<mx:Script>
<![CDATA[
import model.PayablesLocator;
[Bindable] private var locator:PayablesLocator = PayablesLocator.getInstance();
]]>
</mx:Script>
<controls:columns>
<dgc:MDataGridColumn dataField="loadNumber"
headerText="Load"
editable="false"/>
<dgc:MDataGridColumn dataField="carrierName"
headerText="Carrier"
editable="false"/>
<mx:DataGridColumn headerText="Vendor Invoice #"
rendererIsEditor="true"
editorDataField="vendorInvoiceNumber">
<mx:itemRenderer>
<mx:Component>
<mx:HBox width="100%" height="100%" horizontalAlign="center" verticalAlign="middle"
implements="mx.controls.listClasses.IDropInListItemRenderer, mx.managers.IFocusManagerComponent">
<mx:Script>
<![CDATA[
import mx.controls.dataGridClasses.DataGridListData;
import mx.controls.listClasses.BaseListData;
import mx.events.FlexEvent;
private var _listData:DataGridListData;
[Bindable] public var vendorInvoiceNumber:String;
// Implements mx.managers.IFocusManagerComponent
override public function drawFocus(draw:Boolean):void {
invoiceNumberInput.setFocus();
}
// Implements mx.controls.listClasses.IDropInListItemRenderer
override public function get data():Object {
return super.data;
}
override public function set data(value:Object):void {
super.data = value;
invoiceNumberInput.text = data.vendorInvoiceNumber
}
public function get listData():BaseListData {
return _listData;
}
public function set listData(value:BaseListData):void {
_listData = DataGridListData(value);
}
private function onChange(event:Event):void {
data.vendorInvoiceNumber = invoiceNumberInput.text;
}
]]>
</mx:Script>
<mx:TextInput id="invoiceNumberInput"
width="95%"
change="onChange(event)"/>
</mx:HBox>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
<mx:DataGridColumn headerText="Vendor Invoice Date"
rendererIsEditor="true"
editorDataField="vendorInvoiceDate">
<mx:itemRenderer>
<mx:Component>
<mx:HBox width="100%" height="100%" horizontalAlign="center" verticalAlign="middle"
implements="mx.managers.IFocusManagerComponent">
<mx:Script>
<![CDATA[
import mx.events.CalendarLayoutChangeEvent;
[Bindable] public var vendorInvoiceDate:Date;
// Implements mx.managers.IFocusManagerComponent
override public function drawFocus(draw:Boolean):void {
vendorInvoiceDateInput.setFocus();
}
protected function onChange(event:CalendarLayoutChangeEvent):void {
data.vendorInvoiceDate = event.newDate;
}
]]>
</mx:Script>
<mx:DateField id="vendorInvoiceDateInput"
width="95%"
editable="true"
change="onChange(event)"/>
</mx:HBox>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
<mx:DataGridColumn editorDataField="isSelected"
headerText="Select"
rendererIsEditor="true">
<mx:itemRenderer>
<mx:Component>
<mx:HBox width="100%" height="100%" horizontalAlign="center" verticalAlign="middle"
implements="mx.controls.listClasses.IDropInListItemRenderer,mx.managers.IFocusManagerComponent">
<mx:Script>
<![CDATA[
import controller.PayablesController;
import mx.controls.dataGridClasses.DataGridListData;
import mx.controls.listClasses.BaseListData;
private var control:PayablesController = PayablesController.getInstance();
private var _listData:DataGridListData;
[Bindable] public var isSelected:Boolean;
override public function drawFocus(draw:Boolean):void {
selectionCheckBox.setFocus();
}
override public function get data():Object {
return super.data;
}
override public function set data(value:Object):void {
super.data = value;
selectionCheckBox.selected = data.isSelected
}
public function get listData():BaseListData {
return _listData;
}
public function set listData(value:BaseListData):void {
_listData = DataGridListData(value);
}
protected function onChange(event:Event):void {
data.isSelected = selectionCheckBox.selected;
control.updateBatchSelections();
}
]]>
</mx:Script>
<mx:CheckBox id="selectionCheckBox" change="onChange(event)"/>
</mx:HBox>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</controls:columns>

Related

DataGrid Image ItemRenderer --> How to change image source of other rows, not only the selected one

I have an Image in my DataGrid. Its purpose is to play and stop an audio, so I need to change the image source from the "Play" image to the "Stop" image every time I click on it.
I've already accomplished that with the next code:
<?xml version="1.0" encoding="utf-8"?>
<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" title="Audio List"
horizontalScrollPolicy="off" verticalScrollPolicy="auto"
showCloseButton="true" close="closeWindow()">
<mx:Script>
<![CDATA[
import flash.external.ExternalInterface;
import mx.collections.ArrayCollection;
import mx.managers.PopUpManager;
public var dpc:ArrayCollection;
private function closeWindow(){
PopUpManager.removePopUp(this);
ExternalInterface.call("pauseAudio");
}
]]>
</mx:Script>
<mx:Rotate id="rotate" />
<mx:Zoom id="zoom" />
<mx:VBox width="100%" top="20">
<mx:Text fontWeight="bold" top="20" left="20">
<mx:text>Click the play/pause button for listening/pause each audio individually:</mx:text>
</mx:Text>
<mx:DataGrid id="gridAudios" top="60" bottom="0" left="0" width="100%" height="100%" doubleClickEnabled="true">
<mx:columns>
<mx:DataGridColumn headerText="Name" dataField="audioId"/>
<mx:DataGridColumn id="btnCol" dataField="url" headerText="" textAlign="center">
<mx:itemRenderer>
<mx:Component>
<mx:HBox>
<mx:Image click="changeImg(data.url)" toolTip="Play"
id="imgPlayStop" useHandCursor="true"/>
<mx:Script>
<![CDATA[
import mx.states.State;
import mx.collections.ArrayCollection;
[Embed(source='../assets/play-btn-small.png')]
[Bindable]
public var Play:Class;
[Embed(source='../assets/stop-btn-small.png')]
[Bindable]
public var Stop:Class;
private function init():void
{
imgPlayStop.source = Play
var statePlaying:State = new State();
var stateStopped:State = new State();
statePlaying.name="playing";
stateStopped.name="stopped";
var states:Array = new Array();
states.push(statePlaying);
states.push(stateStopped);
imgPlayStop.states = states;
imgPlayStop.currentState = "stopped";
}
private function changeImg(url:String):void{
if (imgPlayStop.currentState == "stopped"){
imgPlayStop.source = Stop;
imgPlayStop.currentState = "playing";
ExternalInterface.call("playAudio", url);
} else {
imgPlayStop.source = Play;
imgPlayStop.currentState = "stopped";
ExternalInterface.call("pauseAudio");
}
}
]]>
</mx:Script>
</mx:HBox>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</mx:columns>
</mx:DataGrid>
</mx:VBox>
</mx:TitleWindow>
But the thing is that I want to change the image source of the other rows of the DataGridColumn.
For example, if I click in the play image of one row it changes to the stop image, everything OK till here.
If now I click the play image of other row, it also changes to the stop image, but the previous row still remains with the stop image, and I want to be only one stope image active.
In other words, I want to give the impression only one audio is playing. So only one of the rows can be with the "Stop" image while the rest must be with the "Play" image.
So, ¿how can I loop through the DataGridColumn items renderer and change their image source every time I click in on of the items renderer?
You can save prev imgPlayStop as public static variable in a Model class and use it
public class Model {
public static var prevImgPlayStop:Image;
}
in your itemRenderer do like this
private function changeImg(url:String):void{
if (Model.prevImgPlayStop) {
Model.prevImgPlayStop.currentState = "stopped";
}
/*your code*/
Model.prevImgPlayStop = imgPlayStop;
}
I post the SOLUTION I founded to my problem:
<?xml version="1.0" encoding="utf-8"?>
<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" title="Audio List"
horizontalScrollPolicy="off" verticalScrollPolicy="auto" width="510" height="340"
showCloseButton="true" close="closeWindow()">
<mx:Script>
<![CDATA[
import flash.external.ExternalInterface;
import mx.collections.ArrayCollection;
import mx.events.FlexEvent;
import mx.managers.PopUpManager;
import mx.controls.Alert;
[Embed(source='../assets/play-btn-small.png')]
var Play:Class;
[Embed(source='../assets/stop-btn-small.png')]
var Stop:Class;
[Blindable]
public var dpc:ArrayCollection;
private function titlewindow1_initializeHandler(event)
{
ExternalInterface.addCallback('onFinishAudio', onFinishAudio);
ExternalInterface.addCallback('onStartAudio', onStartAudio);
}
private function closeWindow(){
PopUpManager.removePopUp(this);
ExternalInterface.call("pauseAudio");
}
private function onFinishAudio(audioId:String) {
for ( var audio:Object in dpc )
{
if (audio.audioId == audioId){
audio.status = 'stopped';
}
}
gridAudios.dataProvider = dpc;
dpc.refresh();
}
private function onStartAudio(audioId:String)
{
for ( var audio:Object in dpc )
{
if (audio.audioId != audioId)
{
if (audio.status == 'playing')
{
audio.status='stopped';
}
} else {
//Alert.show("Dgsg","Error");
audio.status='playing';
}
}
gridAudios.dataProvider = dpc;
dpc.refresh();
}
public function playAudio(audioURL:String, audioId:String){
ExternalInterface.call("playAudio", audioURL, id);
}
public function pauseAudio(){
ExternalInterface.call("pauseAudio");
}
]]>
</mx:Script>
<mx:Rotate id="rotate" />
<mx:Zoom id="zoom" />
<mx:VBox top="0" bottom="0" left="0" right="0" paddingTop="20" paddingLeft="20">
<mx:Text fontWeight="bold" height="20">
<mx:text>Click the play/pause button for listening/pause each audio individually:</mx:text>
</mx:Text>
</mx:VBox>
<mx:DataGrid id="gridAudios" top="50" bottom="20" left="20" right="20" width="100%" doubleClickEnabled="false">
<mx:columns>
<mx:DataGridColumn headerText="Name" dataField="audioId"/>
<mx:DataGridColumn id="btnCol" headerText="" textAlign="center">
<mx:itemRenderer>
<mx:Component>
<mx:HBox horizontalAlign="center">
<mx:Script>
<![CDATA[
protected function image1_clickHandler(event:MouseEvent):void
{
if (data.status=='playing'){
outerDocument.pauseAudio();
data.status='';
}else{
outerDocument.playAudio(data.url,data.audioId);
data.status='playing';
}
}
]]>
</mx:Script>
<mx:Image click="image1_clickHandler(event)"
toolTip="{data.status=='playing' ? 'Stop' : 'Play'}"
useHandCursor="true" source="{data.status=='playing' ? outerDocument.Stop : outerDocument.Play}"/>
</mx:HBox>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</mx:columns>
</mx:DataGrid>
</mx:TitleWindow>
Where the key to the solution is in the source property of the Image object and in the click handler.

Using itemRenderer in mx Datagrid

I have a mx DataGrid with 2 column. The first column has its data rendered in a TextInput and the second column renderer in a ComboBox. When I change the selected value in the ComboBox, I want the TextInput of the same index to have its text changed to the value selected in the ComboBox. Can anyone help me with this? My code is below.
<mx:DataGrid id="myGrid" rowHeight="25" dataProvider="{Testarray}" width="100%" height="205" chromeColor="#D0CCAF" headerHeight="0" showHeaders="false" >
<mx:columns>
<mx:DataGridColumn headerText="My Header 1"
editable="true"
dataField="LBL"
>
<mx:itemRenderer>
<fx:Component>
<mx:HBox horizontalAlign="left" horizontalScrollPolicy="off" verticalScrollPolicy="off">
<s:TextInput id="label_txt" text="{data.LBL}" width="98%"/>
</mx:HBox>
</fx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
<mx:DataGridColumn headerText="My Header 2"
editable="true"
rendererIsEditor="true"
dataField="ALIAS"
>
<mx:itemRenderer>
<fx:Component>
<renderers:comboItemRenderer height="80%" change="comboitemrenderer1_changeHandler(event)" lookupField="ALIAS" labelField="ALIAS" dataProvider="{outerDocument.searchCustomizationComponents_array}">
<fx:Script>
<![CDATA[
import mx.events.DataGridEvent;
import mx.events.ListEvent;
protected function comboitemrenderer1_changeHandler(event:ListEvent):void
{
//WHAT TO PUT HERE?
}
]]>
</fx:Script>
</renderers:comboItemRenderer>
</fx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</mx:columns>
</mx:DataGrid>
I got it myself. Thanks buddies.
I needed to add these 2 lines of codes for the textInput to take the value of the selectedItem int he ComboBox.
protected function comboitemrenderer1_changeHandler(event:ListEvent):void
{
outerDocument.myGrid.dataProvider[outerDocument.myGrid.selectedIndex]['LBL'] = this.selectedItemKey;
outerDocument.myGrid.invalidateList();
}
Also note that the code for my comboitemrenderer below:
<mx:ComboBox
xmlns:mx="http://www.adobe.com/2006/mxml"
dataChange="setSelected()"
change="onSelectionChange(event)"
focusEnabled="true">
<mx:Script>
<![CDATA[
import mx.events.DataGridEvent;
import mx.events.ListEvent;
import mx.controls.dataGridClasses.DataGridListData;
private var _ownerData:Object;
private var _lookupField:String = "value";
// When using this component as an itemEditor rather than an itemRenderer
// then set ' editorDataField="selectedItemKey"' on the column to
// ensure that changes to the ComboBox are propogated.
[Bindable] public var selectedItemKey:Object;
public function set lookupField (value:String) : void {
if(value) {
_lookupField = value;
setSelected();
}
}
override public function set data (value:Object) : void {
if(value) {
_ownerData = value;
setSelected();
}
}
override public function get data() : Object {
return _ownerData;
}
private function setSelected() : void {
if (dataProvider && _ownerData) {
var col:DataGridListData = DataGridListData(listData);
for each (var dp:Object in dataProvider) {
if (dp[_lookupField] == _ownerData[col.dataField]) {
selectedItem = dp;
selectedItemKey = _ownerData[col.dataField];
return;
}
}
}
selectedItem = null;
}
private function onSelectionChange (e:ListEvent) : void {
if (selectedItem && _ownerData) {
var col:DataGridListData = DataGridListData(listData);
_ownerData[col.dataField] = selectedItem[_lookupField];
selectedItemKey = selectedItem[_lookupField];
}
}
]]>
</mx:Script>
</mx:ComboBox>

How to set progress bar for each images in a multiple image uploader?

i am trying to complete a multiple image uploader. i completed the multiple image uploader partially... My project contain a title window,a data grid and 3 buttons(select,upload,cancel).And the data grid contain 3 columns(image preview,name,size). i also put two progress bar. One is showing total images upload progress.. And other is put as item render for each image upload progress seperately(that progress bar showed at the data grid name column and the label of that progress bar is the name of each image)..the first one is working perfectly..But the second item render progress bar is not working..How can i maintain it?? can any one help me?? pls...
my demo is given below..
http://demo.enfintech.net/MultipleFileUpload/
sometimes it is working properly.but more than 4 images are uploaded it is not working.. Means the progress bar is not working properly..but the images are uploaded..
My code is given below
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" creationComplete="init()">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Style>
#namespace s "library://ns.adobe.com/flex/spark";
#namespace mx "library://ns.adobe.com/flex/mx";
global
{
font-weight: bold;
}
</fx:Style>
<fx:Script>
<![CDATA[
import flash.sampler.NewObjectSample;
import flash.utils.flash_proxy;
import flash.utils.setTimeout;
import mx.charts.renderers.AreaRenderer;
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.events.Request;
import mx.utils.OnDemandEventDispatcher;
private var refAddFiles:FileReferenceList=new FileReferenceList;
private var fileReference:FileReference=new FileReference;
private var arrSelectList:Array=new Array();
private var arrRemoveItem:ArrayCollection=new ArrayCollection();
private var serverSideUrl:String="http://demo.enfintech.net/MultipleFileUpload/fileUploader/uploadFile.php";
// private var serverSideUrl:String="http://192.168.1.60/fileUploader/uploadFile.php";
private var list:Array=new Array();
public var urlReq:URLRequest;
private var refAddFilesLength:int=0;
private var timer:Timer;
private var i:int=0;
private var totalSize:Number=0;
private var isSelected:Boolean=false;
private var images:Object;
private var varSize:Number;
private var numPerc:Number;
public var crnt:Number;
private var fileSizeArray:Array=new Array();
private var fileSize:String;
public var maxm:Number;
private var temp:Number=0;
private var uploadBytes:Number=0;
private var temptotal:Number=0;
private var tempVarSize:Number=0;
private var maximumSize:Number=0;
private var currentSize:Number=0;
private var checkCloseClick:Boolean=false;
[Bindable] private var files:ArrayCollection = new ArrayCollection();
private var fileRefUploadFiles:FileReference=new FileReference;
private function init():void
{
Security.loadPolicyFile("http://demo.enfintech.net/crossdomain.xml");
progressBar2.visible=false;
refAddFiles.addEventListener(Event.SELECT,fileRefSelect);
urlReq = new URLRequest(serverSideUrl);
}
private function fileSelect(event:Event):void
{
Alert.show("");
}
private function fileRefSelect(event:Event):void
{
progressBar2.visible=false;
upload1();
isSelected=true;
}
private function fileRefCompleted(event:Event):void
{
fileReference=event.target as FileReference;
fileReference.removeEventListener(Event.COMPLETE, fileRefCompleted);
fileReference.addEventListener(IOErrorEvent.IO_ERROR,error);
if(fileReference.size!=0)
{
tet2.text=fileReference.size.toString();
varSize=fileReference.size;
var tempVarSizeInBytes:Number=varSize;
fileSizeArray.push(tempVarSizeInBytes);
totalSize=varSize;
varSize=varSize/1024;
fileSize=String(varSize.toFixed(1))+"Kb";
tempVarSize=varSize;
if(varSize>1024)
{
varSize=varSize/1024;
fileSize=String(varSize.toFixed(1))+"Mb";
tempVarSize=varSize;
}
else
{
}
temptotal+=tempVarSizeInBytes;
progressBar2.maximum=temptotal;
}
images= {fileName:fileReference.name,size:fileSize, preview:fileReference.data,close:fileReference.name, maximum:fileReference.size, currentValue:0};
files.addItem(images);
select.enabled=false;
if(checkCloseClick==true)
{
upload0.enabled=true;
}
else
{
}
i=0;
}
private function uploadFiles():void
{
if(files.length==0)
{
Alert.show("Please Select file(s)");
}
else
{
var n:int=files.length;
progressBar2.minimum=0;
if(i<n)
{
progressBar2.visible=true;
fileRefUploadFiles=refAddFiles.fileList[i];
fileRefUploadFiles.upload(urlReq);
fileRefUploadFiles.addEventListener(ProgressEvent.PROGRESS,onUploadProgress);
fileRefUploadFiles.addEventListener(Event.COMPLETE,fileRefUploadFilesComplete);
select.enabled=true;
upload0.enabled=false;
}
}
}
public function onUploadProgress(event:ProgressEvent):void
{
numPerc=Math.round(((event.bytesLoaded+uploadBytes)/temptotal)*100);
files[i].currentValue=event.bytesLoaded;
files[i].maXimumValue=event.bytesTotal;
progressBar2.setProgress(uploadBytes+event.bytesLoaded,temptotal);
progressBar2.validateNow();
progressBar2.label=("UPLOADING "+numPerc.toString()+"% ("+(i+1).toString()+"/"+list.length.toString()+")");
}
private function fileRefUploadFilesComplete(event:Event):void
{
uploadBytes=uploadBytes+Number(fileSizeArray[i]);
i++;
uploadFiles();
}
public function upload1():void
{
list=refAddFiles.fileList;
var i:int=0;
var n:int=list.length;
for(i; i < refAddFiles.fileList.length; i++)
{
list[i].addEventListener(ProgressEvent.PROGRESS,uploadItemRender);
currentSize=crnt;
list[i].addEventListener(Event.COMPLETE, fileRefCompleted);
list[i].load();
}
}
private function uploadItemRender(event:ProgressEvent):void
{
maximumSize=event.bytesTotal;
currentSize=event.bytesLoaded;
}
public function removeItem():void
{
var item:int=dgMain.selectedIndex;
files.removeItemAt(item);
}
private function cancelClick():void
{
fileRefUploadFiles.cancel();
if(files.length!=0)
{
files.removeAll();
fileRefUploadFiles.data.clear();
progressBar2.enabled=false;
}
}
private function browsebtn():void
{
var arr:Array = [];
arr.push(new FileFilter("Images", ".gif;*.jpeg;*.jpg;*.png"));
// fileReference.browse(arr);
refAddFiles.browse(arr);
}
private function titleWindowClose():void
{
var item:int=dgMain.selectedIndex;
files.removeAll();
progressBar2.visible=false;
checkCloseClick=true;
select.enabled=true;
}
]]>
</fx:Script>
<s:TitleWindow x="204" y="10" width="520" height="325" id="titleWindow"
skinClass="TitleSkin" title="File Uploader" close="titleWindowClose()">
<mx:DataGrid id="dgMain" x="0" y="0" width="518" height="237" allowMultipleSelection="true"
dataProvider="{files}" fontFamily="Arial" fontSize="12" headerHeight="0"
horizontalScrollPolicy="off" variableRowHeight="true">
<mx:columns>
<mx:DataGridColumn dataField="preview" headerText="Preview" width="40" paddingLeft="5" itemRenderer="ImageDatagrdItmRndr">
</mx:DataGridColumn>
<mx:DataGridColumn dataField="fileName" headerText="Name" width="380" itemRenderer="itmRndrPrgrsBar"/>
<mx:DataGridColumn dataField="size" headerText="Size" width="60"/>
<mx:DataGridColumn id="close" headerText="Size" width="40" itemRenderer="buttonClose"/>
</mx:columns>
</mx:DataGrid>
<mx:ProgressBar id="progressBar2" x="-1" y="237" width="518" barColor="haloblue"
labelPlacement="center" mode="manual" themeColor="#eaeaea"
trackColors="[white,halosilver]"/>
<s:Button id="select" bottom="5" width="87" height="30" label="Select files"
click="browsebtn()" fontFamily="Arial" fontSize="12" horizontalCenter="-91" skinClass="Skin.setButtonSkin"
/>
<s:Button id="upload0" bottom="5" width="79" height="30" label="Upload" click="uploadFiles()"
fontFamily="Arial" fontSize="12" horizontalCenter="0" skinClass="Skin.setButtonSkin"/>
<s:Button id="cancel" bottom="5" width="79" height="30" label="Cancel" fontFamily="Arial"
fontSize="12" horizontalCenter="91" skinClass="Skin.setButtonSkin"/>
</s:TitleWindow>
<s:VGroup>
<s:Label id="tet" color="red" visible="false"/>
<s:Label id="tet2" color="red"/>
</s:VGroup>
</s:Application>
my item render for progressbar is
<?xml version="1.0" encoding="utf-8"?>
<s:MXDataGridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
focusEnabled="true" xmlns:aaronhardy="aaronhardy.*">
<fx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.events.FlexEvent;
protected function progressBar1_updateCompleteHandler(event:FlexEvent):void
{
SparkProgressBar.maximum=data.maximum;
SparkProgressBar.value=data.currentValue;
}
]]>
</fx:Script>
<aaronhardy:ProgressBar id="SparkProgressBar" maximum="{data.maximum}" minimum="0" skinClass="aaronhardy.ProgressBarSkin" left="0" right="0" top="0" bottom="0" updateComplete="progressBar1_updateCompleteHandler(event)"/>
<s:Label id="lblData" left="0" right="0" text="{dataGridListData.label}" verticalCenter="0"/>
</s:MXDataGridItemRenderer>
And the image itemrender is
<?xml version="1.0" encoding="utf-8"?>
<s:MXDataGridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
focusEnabled="true">
<fx:Script>
<![CDATA[
]]>
</fx:Script>
<!-- <s:Label id="lblData" top="0" left="0" right="0" bottom="0" text="{dataGridListData.label}" />-->
<mx:Image left="5" width="31" height="20" source="{data.preview}"/>
</s:MXDataGridItemRenderer>
There are good site here. I wish to be helpful for you.
multiple-file-upload-with-as3-and-php
Flash-AS3-FileReference-Select-and-Upload-Multiple-Files

Flex 3 DataGrid Tab Order

I've been trying to get the tab order to work on this datagrid for some time now and I can't figure out what I am doing wrong. Can anyone spot it?
<?xml version="1.0" encoding="utf-8"?>
<controls:MDataGrid xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:controls="com.iwobanas.controls.*"
xmlns:dgc="com.iwobanas.controls.dataGridClasses.*"
dataProvider="{locator.vendorInvoices}">
<mx:Script>
<![CDATA[
import com.model.PayablesLocator;
[Bindable] private var locator:PayablesLocator = PayablesLocator.getInstance();
]]>
</mx:Script>
<controls:columns>
<dgc:MDataGridColumn dataField="loadNumber"
headerText="Load"/>
<dgc:MDataGridColumn dataField="carrierName"
headerText="Carrier"/>
<mx:DataGridColumn dataField="vendorInvoiceNumber"
headerText="Vendor Invoice #"
rendererIsEditor="true"
editorDataField="vendorInvoiceNumber">
<mx:itemRenderer>
<mx:Component>
<mx:HBox width="100%" height="100%" horizontalAlign="center" verticalAlign="middle">
<mx:Script>
<![CDATA[
protected function invoiceNumberInput_changeHandler(event:Event):void {
data.vendorInvoiceNumber = invoiceNumberInput.text;
}
]]>
</mx:Script>
<mx:TextInput id="invoiceNumberInput"
text="{data.vendorInvoiceNumber}"
editable="true"
width="95%"
change="invoiceNumberInput_changeHandler(event)"/>
</mx:HBox>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
<mx:DataGridColumn dataField="vendorInvoiceDate"
headerText="Invoice Date"
rendererIsEditor="true"
editorDataField="vendorInvoiceDate">
<mx:itemRenderer>
<mx:Component>
<mx:HBox width="100%" height="100%" horizontalAlign="center" verticalAlign="middle">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.events.CalendarLayoutChangeEvent;
import mx.events.CloseEvent;
protected function invoiceDateChanged(event:CalendarLayoutChangeEvent):void {
data.vendorInvoiceDate = event.newDate;
}
]]>
</mx:Script>
<mx:DateField id="vendorInvoiceDateInput"
selectedDate="{data.vendorInvoiceDate}"
editable="true"
width="95%"
change="invoiceDateChanged(event)"/>
</mx:HBox>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
<mx:DataGridColumn dataField="isSelected"
headerText="Select"
rendererIsEditor="true"
editorDataField="isSelected">
<mx:itemRenderer>
<mx:Component>
<mx:HBox horizontalAlign="center" verticalAlign="middle">
<mx:Script>
<![CDATA[
import com.controller.PayablesController;
private var control:PayablesController = PayablesController.getInstance();
private function onCheckboxClick():void {
data.isSelected = selectionCheckBox.selected;
control.updateBatchSelections();
}
]]>
</mx:Script>
<mx:CheckBox id="selectionCheckBox"
selected="{data.isSelected}"
change="onCheckboxClick()"/>
</mx:HBox>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</controls:columns>
I'm trying to get the tab order as follows for each row: Vendor Invoice > Invoice Date > Select, but when I try to tab to the next field it jumps to the URL of the browser (IE in this case). I've tried a bunch of things found on the net, but none of them have seemed to work.
Any help would be greatly appreciated.
--Charly
There is no built in support for this. This will work if you have editable cells, and that too it will only work if your editors implement IFocusManagerComponent. (In this case your editors are wrapped inside HBoxes which do not). If you were using the spark datagrid, you could use : http://squaredi.blogspot.com/2011/09/precision-focus-control-within-spark.html
Resulting working code:
<?xml version="1.0" encoding="utf-8"?>
<controls:MDataGrid xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:controls="com.iwobanas.controls.*"
xmlns:dgc="com.iwobanas.controls.dataGridClasses.*"
dataProvider="{locator.vendorInvoices}"
editable="true">
<mx:Script>
<![CDATA[
import com.model.PayablesLocator;
[Bindable] private var locator:PayablesLocator = PayablesLocator.getInstance();
]]>
</mx:Script>
<controls:columns>
<dgc:MDataGridColumn dataField="loadNumber"
headerText="Load"
editable="false"/>
<dgc:MDataGridColumn dataField="carrierName"
headerText="Carrier"
editable="false"/>
<mx:DataGridColumn dataField="vendorInvoiceNumber"
headerText="Vendor Invoice #"
rendererIsEditor="true"
editorDataField="value">
<mx:itemRenderer>
<mx:Component>
<mx:HBox width="100%" height="100%" horizontalAlign="center" verticalAlign="middle"
implements="mx.managers.IFocusManagerComponent">
<mx:Script>
<![CDATA[
[Bindable] public var value:String;
override public function drawFocus(draw:Boolean):void {
invoiceNumberInput.setFocus();
}
]]>
</mx:Script>
<mx:TextInput id="invoiceNumberInput"
text="{value}"
width="95%"/>
</mx:HBox>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
<mx:DataGridColumn dataField="vendorInvoiceDate"
headerText="Invoice Date"
rendererIsEditor="true"
editorDataField="value">
<mx:itemRenderer>
<mx:Component>
<mx:HBox width="100%" height="100%" horizontalAlign="center" verticalAlign="middle"
implements="mx.managers.IFocusManagerComponent">
<mx:Script>
<![CDATA[
[Bindable] public var value:Date;
override public function drawFocus(draw:Boolean):void {
vendorInvoiceDateInput.setFocus();
}
]]>
</mx:Script>
<mx:DateField id="vendorInvoiceDateInput"
selectedDate="{value}"
editable="true"
width="95%"/>
</mx:HBox>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
<mx:DataGridColumn editorDataField="isSelected"
headerText="Select"
rendererIsEditor="true">
<mx:itemRenderer>
<mx:Component>
<mx:HBox width="100%" height="100%" horizontalAlign="center" verticalAlign="middle"
implements="mx.controls.listClasses.IDropInListItemRenderer,mx.managers.IFocusManagerComponent">
<mx:Script>
<![CDATA[
import com.controller.PayablesController;
import mx.controls.dataGridClasses.DataGridListData;
import mx.controls.listClasses.BaseListData;
private var control:PayablesController = PayablesController.getInstance();
private var _listData:DataGridListData;
[Bindable] public var isSelected:Boolean;
override public function drawFocus(draw:Boolean):void {
selectionCheckBox.setFocus();
}
override public function get data():Object {
return super.data;
}
override public function set data(value:Object):void {
super.data = value;
selectionCheckBox.selected = data.isSelected
}
public function get listData():BaseListData {
return _listData;
}
public function set listData(value:BaseListData):void {
_listData = DataGridListData(value);
}
protected function onChange(event:Event):void {
data.isSelected = selectionCheckBox.selected;
control.updateBatchSelections();
}
]]>
</mx:Script>
<mx:CheckBox id="selectionCheckBox" change="onChange(event)"/>
</mx:HBox>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</controls:columns>

ItemRollOver with a custom ToolTip

I have this custom toolTip:
<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
implements="mx.core.IToolTip"
creationPolicy="all"
cornerRadius="4" borderStyle="solid" backgroundColor="#FFFFFF"
creationComplete="init()" width="100" height="100">
<fx:Script>
<![CDATA[
import mx.core.IToolTip;
public var arrItemsKits:Array=[];
public var _text:String;
public function get text():String {
return _text;
}
public function set text(value:String):void {
}
protected function init():void
{
grid.dataProvider=arrItemsKits;
}
]]>
</fx:Script>
<mx:DataGrid id="grid" width="100%" height="100%">
<mx:columns>
<mx:DataGridColumn headerText="Code" dataField="itemPartNumber"/>
<mx:DataGridColumn headerText="Description" dataField="kitItemsNotes"/>
</mx:columns>
</mx:DataGrid>
</mx:VBox>
and i want it to fire it when i roll the mouse over a row from a datagrid, so i need to add an event listener(toolTipCreate) to the row of that grid.
Any ideas how can i solve this?
Thanks
Check out this
<!-- myDataGridTest.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
import mx.events.ListEvent;
import mx.core.IToolTip;
import mx.events.ToolTipEvent;
// holds the currently highlighted item
private var highlightedItem:Object;
// event listener to get our hands on the currently highlighted item.
private function getHighlightedItem(e:ListEvent):void {
highlightedItem = e.itemRenderer.data;
// Quick n dirty way to force the ToolTipManager to refresh our tooltip.
// We need to dispatch this by hand because the pointer never leaves myDataGrid
// between successive highlights.
myDataGrid.dispatchEvent(new MouseEvent(MouseEvent.MOUSE_OUT));
}
private function createTooltip(e:ToolTipEvent):void {
var tt:MyCustomTooltip = new MyCustomTooltip();
tt.firstName = highlightedItem.name;
tt.lastName = highlightedItem.surname;
// Contract with the tooltip manager: if it finds an IToolTip instance attached to
// the event, it uses that instance instead of creating the standard one.
e.toolTip = tt;
}
]]>
</mx:Script>
<mx:DataGrid id="myDataGrid" toolTip=" " toolTipCreate="createTooltip(event)" itemRollOver="getHighlightedItem(event)">
<mx:dataProvider>
<mx:Object name="john" surname="doe"/>
<mx:Object name="mike" surname="smith"/>
</mx:dataProvider>
</mx:DataGrid>
</mx:Application>
<!-- MyCustomTooltip.mxml -->
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" implements="mx.core.IToolTip"
backgroundColor="yellow" backgroundAlpha="0.6">
<mx:Script>
<![CDATA[
private var _firstName:String;
private var _lastName:String;
// Dummy implementations to comply with mx.core.IToolTip
public function get text():String {return null;}
public function set text(value:String):void {}
// properties and functions
public function set firstName(value:String):void {
_firstName = value;
invalidateProperties();
}
public function set lastName(value:String):void {
_lastName = value;
invalidateProperties();
}
override protected function commitProperties():void {
fName.text = _firstName;
lName.text = _lastName;
}
]]>
</mx:Script>
<mx:Label x="0" y="0" id="fName"/>
<mx:Label x="0" y="20" id="lName"/>
</mx:Canvas>
.
.
Or try something like this
.
.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="doInit();">
<mx:Script>
<!![CDATA[import mx.collections.ArrayCollection; // this holds the grid data
[Bindable]
private var myData:ArrayCollection = new ArrayCollection();private function doInit():void{
myData.addItem({fname:"Joe",lname:"Bloggs"});
myData.addItem({fname:"Joe1",lname:"Bloggs"});
}
private function buildToolTip(item:Object):String{
var myString:String = "";
if(item != null)
{
myString = myString + "Firstname : " + item.fname + "\n";
myString = myString + "Lastname : " + item.lname + "\n"
}
return myString;
}
]]>
</mx:Script>
<mx:DataGrid id="dGrid" dataProvider="{myData}" visible="true" dataTipFunction="buildToolTip">
<mx:columns>
<mx:DataGridColumn dataField="fname" headerText="FirstName" showDataTips="true" />
<mx:DataGridColumn dataField="lname" headerText="LastName" showDataTips="true" />
</mx:columns>
</mx:DataGrid>
</mx:Application>
I figured it out: On itemRollOver handler you add event.itemRenderer.addEventListener(ToolTipEvent.TOOL_TIP_CREATE, createTT);