2 Replies Latest reply on Feb 22, 2011 12:06 PM by Shongrunden

    Issue Putting Data from ArrayCollection into List


      I'm having trouble getting data that has been pulled from a textArea and put into an ArrayCollection to be displayed in a List.  The data is being saved and then read as a file from local storage.  When I run the application, nothing appears in the created list even though I get no compile-time errors.


      Here is my List code:



       import dh.DataHandling;
       import mx.collections.ArrayCollection;
       import mx.collections.ArrayList;
       import mx.events.FlexEvent;
       import spark.effects.SlideViewTransition;
       private var dataR:DataHandling = new DataHandling();
       protected function button1_clickHandler(event:MouseEvent):void  // pushed home button
       var svt:SlideViewTransition = new SlideViewTransition(300, SlideViewTransition.SLIDE_RIGHT);
       navigator.pushView(views.HomePage, event.relatedObject, svt);
       <!-- Place non-visual elements (e.g., services, value objects) here -->
       <s:Button label="Delete"/>
       <s:Button label="Home" click="button1_clickHandler(event)" skinClass="skins.homeButtonSkin"/>
       <s:Image x="0" y="-80" height="603" source="mainapp1.jpg"/>
       <s:List  id="myCardsList" x="10" y="10" width="1004" height="500" top="0" bottom="0" left="0" right="0"
        dataProvider="{dataR.cards as ArrayCollection}">
       <s:MobileIconItemRenderer label="{data.textTitle}"/>



      Here's the "saving/reading the file" class used in creating the ArrayCollection:  ( DataHandling.as )



      package dh
       public class DataHandling
       import flash.events.IOErrorEvent;
       import flash.filesystem.File;
       import flash.filesystem.FileMode;
       import flash.filesystem.FileStream;
       import mx.collections.ArrayCollection;
       public var cards:ArrayCollection = new ArrayCollection();
       public var file:File;
       public var fileStream:FileStream;
       public var fileName:String = "Initial String";
       public var directory:String = "SimpleSaveFromAIR";
       public var textTitle:String;
       public function DataHandling()
       public function add():void
       // new object
       var card:Object = new Object();
       card.tcard = textTitle;
       //card.mtext1 = mtext1.text;
       ///card.mtext2 = mtext2.text;
       public function save():void
       // create file object (resolve user's directory, add own directory)
       file = File.documentsDirectory.resolvePath(directory + "\\" + fileName);
       // FileStream for writing the file
       fileStream = new FileStream();
       // open the file in write mode
       fileStream.open(file, FileMode.WRITE);
       // Write the ArrayCollection object of cards to the file
       // close stream
       public function read():void
       // get correct path
       file = File.documentsDirectory.resolvePath(directory + "\\" + fileName);
       // read if exists
       // FileStream for reading the file
       fileStream = new FileStream();
       // open the file in read mode
       fileStream.open(file, FileMode.READ);
       // Read the ArrayCollection object of cards from the file
       cards = fileStream.readObject() as ArrayCollection;
       //close Stream
       // some sample data + save if file does not exist
       cards = new ArrayCollection();
       var card:Object = new Object();
       card.tcard = "Sample Title";
       card.mtext1 = "Sample Text";