Skip to main content
Participant
August 28, 2011
Question

Flex mobile while loop silently failing (halp!)

  • August 28, 2011
  • 1 reply
  • 775 views

Here is my code - fairly simple, just trying to add years to an array to use as a data object later.

     public var yearsvar:Array;

     private function createDates():void

     {

    

     var x:int = new int(1);

     var curYear:Date = new Date();

     var z:int = new int(curYear.fullYear);

     var i:int = new int(z-90);

    

     while (i < z)

     {

          yearsvar = i;

          i++;

          x++;

     }

     year_dd.dataProvider = new ArrayCollection(yearsvar);

}

Using some debugging i've narrowed it down to something to do with the yearsvar = i; statement - it gives me no errors and bombs out of the function silently. I'm at a loss as this seems like it should work. Perhaps I'm going crazy and have missed something.

This topic has been closed for replies.

1 reply

Participating Frequently
August 29, 2011

I'm sure there are dozens of ways to do this, here is one. Sorry about the formatting, this is through email.

public var acYearList:ArrayCollection = new ArrayCollection();

//Populate the yearlist arraycollection with years.

protected function CreateYearList():void

{

var dCurrentDate:Date = new Date();

var nYearCount:int = dCurrentDate.fullYear;

//Add 90 to the current year for the total, add one to offset for the LT (<)

var nYearTotal:int = nYearCount + 90 + 1;

//Loop until year count equals year total.

for (nYearCount; nYearCount < nYearTotal; nYearCount++)

{

//Add the current year to the arraycollection.

acYearList.addItem(nYearCount);

}

}

<!-- Years in a List -->

<s:DropDownList id="ddlYears" dataProvider="" />

Hope this helps some.