Java Developer
Java Developer

Reputation: 1901

How to Convert String into ArrayCollection in Flex?

Actually my Flex Application ..Sample code

private var selectedDays:String = null;
            protected function selectRepeatedDays(event:MouseEvent):void
            {
                selectedDays = new String();
                if(MON.selected==true)
                {
                    selectedDays += "MONDAY,";
                    Alert.show("Monday  :"+selectedDays);
                }
                if(TUE.selected==true)
                {
                    selectedDays +=  "TUESDAY,";
                }
                if(WED.selected==true)
                {
                    selectedDays += "WEDNESDAY,";
                    Alert.show("Monday  :"+selectedDays);
                }
                if(THU.selected==true)
                {
                    selectedDays += "THURSDAY,";
                }

}
var arr:ArrayCollection = new ArrayCollection();
arr = selectedDays.substr(0, selectedDays.length-1).toString();

Alert.show(arr.lenth)

But it is not convert... the Alert Statement Not Prompt .. So How to Convert This String into ArrayCollection...

Upvotes: 1

Views: 2229

Answers (2)

Sasikumar Murugesan
Sasikumar Murugesan

Reputation: 4520

use below code snippet to convert String to ArrayCollection

  1. Convert String to Array using split method

    var array:Array = selectedDays.split(",");
    
  2. Convert Array to ArrayCollection

    var selectedDaysArr:ArrayCollection = new ArrayCollection(array);
    

Upvotes: 1

HugoLemos
HugoLemos

Reputation: 473

Use the method split to convert the String to Array:

var array:Array = selectedDays.split(",");

Then (if needed yet) add each item of Array to the ArrayCollection:

var arr:ArrayCollection = new ArrayCollection();
for each (var str:String in array) {
    arr.addItem(str);
}

Upvotes: 2

Related Questions