Search code examples
apache-flexactionscript-3

Is it possible to store an array in a DataGridColumn in Flex?


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


Solution

  • 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>