Reputation: 1901
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
Reputation: 4520
use below code snippet to convert String to ArrayCollection
Convert String to Array using split method
var array:Array = selectedDays.split(",");
Convert Array to ArrayCollection
var selectedDaysArr:ArrayCollection = new ArrayCollection(array);
Upvotes: 1
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