views:

144

answers:

2

Hello Everyone,

I have a datagrid column with a button that opens a modal dialog box allowing the user to upload multiple files. In the code below, the browseAndUpload() method does that. When the user finished uploading files and closes the upload box the closeUpload() method is called. I know for a fact that the uploaded files are being copied into arrFiles.

The problem I am having is that the repeater will not show the files in arrFiles. Here is the code:

<mx:DataGridColumn id="dgcUpload" width="42" headerText="Uploaded Files"
    editable="false">
    <mx:itemRenderer>
        <mx:Component>
            <mx:VBox>
                <mx:Script>
                    <![CDATA[
                        [Bindable]public var arrFiles:ArrayCollection = new ArrayCollection();
                        public var fileUpload:FileUpload = new FileUpload();

                        private function browseAndUpload(event:MouseEvent):void
                        {
                            fileUpload = FileUpload(PopUpManager.createPopUp(this, FileUpload, true));

                            fileUpload.addEventListener(CloseEvent.CLOSE, closeUpload);
                            fileUpload["btnClose"].addEventListener("click", closeUpload);
                        }

                        private function closeUpload(event:Event):void
                        {
                            arrFiles = fileUpload.arrFiles;
                        }
                    ]]>
                </mx:Script>
                <mx:HBox paddingLeft="3" paddingRight="3">
                    <mx:Button width="36" label="..." click="browseAndUpload(event)"/>
                </mx:HBox>
                <mx:Repeater id="rpFiles" dataProvider="{arrFiles}">
                    <mx:Label text="{FileVO(rpFiles.currentItem).name}"/>
                </mx:Repeater>
            </mx:VBox>
        </mx:Component>
    </mx:itemRenderer>
</mx:DataGridColumn>

Thank you in advance for any insight,

Orville

A: 
  • You are assigning fileUpload.arrFiles directly to arrFiles. Is the former an Array or ArrayCollection? You might need to do arrFiles = new ArrayCollection(fileUpload.arrFiles);

That being said, I hate flex binding and generally avoid it because it can be unreliable. In your case, I'd write my own AS3 component that implements the ItemRenderer and then assign the repeater's dataprovider manually when it changes. You will have more control over the behavior if you do it that way. And a much easier time debugging.

Glenn
Thank you for your help Glenn. It looks like I might have to write an AS3 component as you suggested.
+1  A: 

Got it! I made the following changes:

private function closeUpload(event:Event):void
{
    arrFiles = fileUpload.arrFiles;
    rpFiles.dataProvider = arrFiles;
}


<mx:Repeater id="rpFiles">
    <mx:Label text="{FileVO(rpFiles.currentItem).name}"/>
</mx:Repeater>
You're welcome.
Glenn