PDA

View Full Version : Obj Data Binding Problem..


hpnotiqtymes
05-02-2009, 04:16 PM
Hi All,

Im creating a multiple file upload system and so far it works perfect accept for one thing..im trying to implement a itemRenderer for each object in the form of a progress bar but every time i try to bind the data.obj to the progress column of the datagrid i made to display the info i get this error:

warning: unable to bind to property 'object' on class 'Object' (class is not an IEventDispatcher)

ive tried using ObjectProxy, creating a seperate class that extends EventDispatcher and Object to hold the variables that are going to be bound and yet i still get the error here is my mxml:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="600" height="500">
<mx:Script>
<![CDATA[
import mx.utils.ObjectProxy;
import mx.events.CollectionEvent;
import mx.collections.ArrayCollection;
import flash.net.FileReferenceList;

private var imageTypes:FileFilter = new FileFilter ( "Images (*.jpg)", "*.jpg");
private var allTypes:Array = new Array ( imageTypes );
private var fileRef:FileReferenceList = new FileReferenceList();
private var imageSelected:Boolean;
[Bindable] private var arrayCollection:ArrayCollection = new ArrayCollection();
[Bindable] private var tf:ObjectProxy;
private function addImages (event:MouseEvent):void
{
//arrayCollection.removeAll();
//arrayCollection.refresh();
fileRef.addEventListener ( Event.SELECT, selectHandler );
fileRef.browse ( allTypes );
}
private function selectHandler ( e:Event ):void
{
var fileList:Array = fileRef.fileList;
for ( var i:Number = 0; i < fileList.length; i++ )
{
var file:FileReference = FileReference ( fileList[i] );
var tf:TheFile = new TheFile();
tf.name = file.name;
tf.size = file.size;
tf.obj = file;
arrayCollection.addItem ( tf );
}
}
private function uploadImages (event:MouseEvent):void
{
var fileList:Array = fileRef.fileList;
for ( var i:Number = 0; i < fileList.length; i++ )
{
var urlRequest:URLRequest = new URLRequest ( "upload.php" );
var file:FileReference = FileReference ( fileList[i] );
file.upload ( urlRequest );
}
arrayCollection.removeAll();
arrayCollection.refresh();
}
]]>
</mx:Script>
<mx:Style source="styles.css"/>
<mx:Panel layout="absolute" title="IMAGE QUEUE" width="523" horizontalAlign="center" horizontalCenter="-9" height="412" verticalCenter="2">
<mx:Button id="upload" click="uploadImages(event)" y="339" label="UPLOAD" height="31" width="245" fontWeight="bold" fontFamily="Arial" horizontalCenter="129"/>
<mx:Button id="browse" click="addImages(event)" y="339" label="BROWSE" height="31" width="245" fontWeight="bold" fontFamily="Arial" horizontalCenter="-128"/>
<mx:DataGrid id="dataGrid" dataProvider="{arrayCollection}" y="15" width="500" horizontalCenter="0" height="312">
<mx:columns>
<mx:DataGridColumn headerText="Name" dataField="name" width="100"/>
<mx:DataGridColumn headerText="Size" dataField="size" width="30"/>
<mx:DataGridColumn headerText="Progress" dataField="obj" width="150" paddingLeft="2">
<mx:itemRenderer>
<mx:Component>
<mx:HBox verticalAlign="middle">
<mx:ProgressBar label="" height="6" source="{data.obj}"/>
</mx:HBox>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</mx:columns>
</mx:DataGrid>
</mx:Panel>

</mx:Application>

any help would be appreciated thanks in advanced..

wvxvw
05-02-2009, 07:05 PM
data is a property of HBox, or just any other UIComponent, and it is of the Object type, so, you cannot bind to it, as binding requires setter to dispatch an event. Though, you may bind to function, or, just to a different property.
Or even more simple, if your are sure that data.obj may dispatch events, override the data setter in your item renderer and add event listener to obj. In that listener manage progress bar's display. Something like this:
<mx:HBox verticalAlign="middle">
<mx:Script>
<![CDATA[
override public function set data(value:Object):void
{
(value.obj as IEventDispatcher).addEventListener("someEvent", obj_someEventHandler);
// or maybe it's TheFile?
super.data = value;
}
private function obj_someEventHandler(event:Event):void
{
var file:TheFile = event.currentTarget as TheFile;
// what is TheFile? Does it have some bytesTotal / bytesLoaded properties?
myProgressBar.setProgress(file.bytesTotal, file.bytesLoaded);
}
.....