views:

16

answers:

1
+2  Q: 

Loop in Adobe Flex

Hi guys,

I'm new to Flex programming.. and I need to do some iteration.

How do I perform loops in Flex?

And does Flex has "switch case"?

Thanks guys

+1  A: 

For Loops in Flex implemented as follows:

var i:int;
for (i = 0; i < 5; i++)
{
    trace(i);
}

You can also do for each loops as :

var myArray:Array = ["name1", "name2", "name3"];
for each (var item in myArray)
{

}

While Loops:

var i:int = 0;
while (i < 10)
{
    i++;
}

also Yes Flex does support switch statements these can be implemented as follows

var someDate:Date = new Date();
var dayNum:uint = someDate.getDay();
switch(dayNum)
{
    case 0:
        trace("Sunday");
        break;
    case 1:
        trace("Monday");
        break;
    case 2:
        trace("Tuesday");
        break;
    case 3:
        trace("Wednesday");
        break;
    case 4:
        trace("Thursday");
        break;
    case 5:
        trace("Friday");
        break;
    case 6:
        trace("Saturday");
        break;
    default:
        trace("Out of range");
        break;
}

remember when writing this funcionality in flex it has to be contained within the script tags**

Chris
Thanks Chris.. seems to be very alike Java and C :)
Santucci
Btw I cannot vote up to your question yet until I receive one more vote to my question =p
Santucci