0
votes

I want to seperate arraycollection based on string in flex . i have an arraycollection items look like {[(name:aa),(name:bb),(name:ae),(name:cc),(name:bd)}], now i want to seperate this arraycollection based on 'a' and all 'a' items to be add in seperate arraycollection.

Arraycollection declaration like

[Bindable]
public var arr:ArrayCollection=new ArrayCollection([{name:"cards/a.png"},{name:"cards/b.png"},{name:"cards/ac.png"},{name:"af.png"},{name:"ad.png"},{name:"cards/bb.png"}]);
1

1 Answers

0
votes

Your arraycollection construction should be new ArrayCollection([{name:"aa"},{name:"bb"}]); "(" it should be "{".

    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <fx:Script>
        <![CDATA[
         import mx.collections.ArrayCollection;
         import mx.controls.Alert;
         import mx.utils.ObjectUtil;

        public var wordCollection:ArrayCollection = new ArrayCollection([{name:"aa"}, {name:"bb"}, 
        {name:"ae"}, {name:"cc"}, {name:"bd"}]);

        public var charACollection:ArrayCollection = new ArrayCollection();
        public var charBCollection:ArrayCollection = new ArrayCollection();
        public var charCCollection:ArrayCollection = new ArrayCollection();

        private function createCompleteHandler():void
        {
            wordCollection.filterFunction = splitByChars;
            wordCollection.refresh();

            trace(ObjectUtil.toString(charACollection));
            trace(ObjectUtil.toString(charBCollection));
            trace(ObjectUtil.toString(charCCollection));
        }

        private function splitByChars(item:Object):Boolean
        {
            var char:String = item.name.toString().charAt(0);

            if (char.toLowerCase() == "a")
            {
                charACollection.addItem(item);
            }
            else if (char.toLowerCase() == "b")
            {
                charBCollection.addItem(item);
            }
            else if (char.toLowerCase() == "c")
            {
                charCCollection.addItem(item);
            }

            return true;
        }


        ]]>
    </fx:Script>
</s:Application>