2 Replies Latest reply on Feb 24, 2009 7:12 AM by alice_data

    for...each to for..in problem

    alice_data Level 1

      I have the code as in the following, but I found that there is a major problem here. Since I use for each, it seems that the index always resets to 0 to each item, so I always run into the issue of when I add elements that I don't want to add, such as duplicate entries to the dataGrid.
      I tried to change it to for...in as in the Actionscript 3 manual from Adobe, but it kept telling me this:

      1067: Implicit coercion of a value of type String to an unrelated type mx.controls:CheckBox

      Can anyone please help me figure out what I am supposed to do here? I have finally got everything to for each since I have to use a double for loop to reiterate the selections of my checkboxes.

      Thanks in advance.

        • 1. Re: for...each to for..in problem
          Richard_Abbott Level 3

          no immediate thoughts about the cast problem, but unless I am miscounting the number of {} then you are testing
          else if (obj.selected == false)
          inside the condition
          • 2. for...each to for..in problem
            alice_data Level 1
            Hi, Richard:

            I think what I really wanted to do is to see the index of the element I try to test, which is obj2.selected. However, right now, the index always returns me a -1, which means not exist even though they have already been written to the "dataGrid." This causes me great agony having to recreate the contents of the dataGrid every time I populate the checkboxes. I am wondering if it is possible to allow me create a construct to return 0 1 -1 if I check 3 checkboxes, since the first two already exist. I am not sure if I know how to do it though.

            I am thinking of something that is like the search function, that if the element is already in the array, then keep what is on the dataGrid, since users are apt to edit what they see on the screen, and I don't want users having to hit a save button every time.

            For visibility and error checking purposes, I am only leaving the two sections of code that I am trying to process the "checkboxes" here.