2 Replies Latest reply on Aug 23, 2010 5:26 PM by RKaster

    Problem with ArrayCollection repitition.

    RKaster Level 1

      I'm going through Flex in a Week right now but I've decided to take a break and develop a little application to test my knowledge. I was building a sort of blog-like application, but that's a little besides my problem.

      If you remember in day two where you build Value Objects and populate them with the employee XML info, I was doing the exact same thing in my own application. Everything works fine, from the data getting through succesfully, and actually rendering on a Drop Down list on my application when I run it. The only problem is, it will only display the information on the last array.

      For example, here's a simple but similar XML:

      <BlogEntries>

           <Blog>

                <Title> Gill Pickle </Title>

                <BlogInput> Several paragraphs of something or something. </BlogInput>

           </Blog>

           <Blog>

                <Title> Fiddle Sticks </Title>

                <BlogInput> Some more Paragraphs. </BlogInput>

           </Blog>

           <Blog>

                <Title> Gumball </Title>

                <BlogInput>More and more paragraphs </BlogInput>

           </Blog>

           <Blog>

                <Title> Pointless </Title>

                <BlogInput> Sicks of writing this. </BlogInput>

           </Blog>

      </BlogEntries>

       

      If I were to load this in my application, only the last <Blog> of Array data will display. In other words, the DropDownList will only display "Pointless" and none of the other Titles. I've been trying to find what it is I'm missing or what it is I did, but I can't think what would cause it to only display the last array. When I went to the Debug perspective, I noticed it was only displaying that last array in my ArrayCollection variable I made to insert in the DataProvider for the DropDownList.

       

      My guess is I somehow managed to clear the previous Array loads before it gets into the DropDownList when it loops in the "for each", but I just have no idea, and how I did that I don't know. I made my program very similar to the one made in Day Two.

       

      I'm hoping someone out there has encountered something similar or might know what I did wrong. Keep in mind that in my application, I avoided throwing the UI into a separate component which I would load into the main.mxml, but I don't see how that would suddenly cause only the last Array to load.

       

      Any suggestions or help would be appreciated.

       

      I'll provide any other information that would be necessary to get this figured out.

        • 1. Re: Problem with ArrayCollection repitition.
          FlexualHealing Level 1

          I have had that problem before, but without seeing the code it is hard to determine what might be going wrong. Could you post it please?

          • 2. Re: Problem with ArrayCollection repitition.
            RKaster Level 1

            here's the main and the associating Value Object class. Ignore the BlogView component. As of now I haven"t told that to do anything.

             

            <<<<- BlogTest.mxml ->>>>

             

            <?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"

             

                           backgroundColor="#B4B4B4"

             

                           creationComplete="blogLink.send()" xmlns:Components="Components.*">

             

             

             

                <fx:Style source="Styles/Test.css"/>

             

                <fx:Script>

             

                    <![CDATA[

             

                        import mx.collections.ArrayCollection;

             

                        import mx.rpc.events.ResultEvent;

             

                        import mx.states.AddItems;

             

             

             

                        import valueObjects.BlogLoad;

             

             

             

                        [Bindable]

             

                        private var blogs:ArrayCollection = new ArrayCollection();

             

             

             

             

             

                        protected function blogLink_resultHandler(event:ResultEvent):void

             

                        {

             

                            var blogData:ArrayCollection = event.result.BlogInfo.BlogEntry;

             

                            var blogUp:BlogLoad;

             

                           

             

                            for each(var blg:Object in blogData)

             

                            blogUp = new BlogLoad();

             

                            blogUp.Title = blg.Title;

             

                            blogUp.Date = blg.Date;

             

                            blogUp.BlogInp = blg.BlogInp;

             

                            blogUp.Todays = blg.Todays;

             

                            blogs.addItem(blogUp);

             

                        }

             

                    ]]>


                </fx:Script>
                <fx:Declarations>
                   
                    <s:HTTPService
                        id="blogLink"
                        url="BlogEnt.xml"
                        result="blogLink_resultHandler(event)"
                        />
                       
                </fx:Declarations>
                <Components:BlogView
                    visible="false"
                    />
                <s:DropDownList dataProvider="{blogs}" labelField="Title"></s:DropDownList>
                <s:BorderContainer x="83" y="33" width="481" height="412" backgroundColor="#838383">
                    <mx:Form x="24" y="10" backgroundColor="#FFFFFF" width="215" height="377">
                        <mx:FormItem backgroundColor="#DADADA" width="181" height="242">
                           
                            <mx:Repeater id="repD" dataProvider="{blogs}" width="0" height="0">
                           
                                <s:Label text="{repD.currentItem.Title}" color="#000000"/>
                               
                            </mx:Repeater>
                           
                        </mx:FormItem>
                       
                    </mx:Form>
                    <mx:Image x="354" y="10"/>
                   
                    <s:Label x="293" y="74" text="Today's Thought" fontWeight="bold" fontSize="19"/>
                   
                    <s:TextArea x="280" y="99" height="78"/>
                   
                </s:BorderContainer>
            </s:Application>

             

             

            <<<<<<- BlogLoad.as ->>>>>>>>>

             

            package valueObjects
            {
                public class BlogLoad
                {
                    public var Title:String;
                    public var Date:String;
                    public var BlogInp:String;
                    public var Todays:String;
                   
                    public function BlogLoad()
                    {
                    }
                }
            }