20 Replies Latest reply on Aug 29, 2011 1:45 PM by Ned Murphy

    for (i=1; i<CV.length; i++) {

    Ron Colmen Level 2

      How can I get this to work?

       

      var CV:Array = [a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8]];

       

      for (i=1; i<CV.length; i++) {

      if (CV[i]== "JANUARY"){

      colorchange.setRGB(0x000000);

      }

      if (CV[i]== "FEBRUARY"){

      colorchange.setRGB(0xFFFFFF);

      }

      //trace (CV[i]) // shows undefined

      }

        • 1. Re: for (i=1; i<CV.length; i++) {
          Ned Murphy Adobe Community Professional & MVP

          What is this supposed to be:

           

             var CV:Array = [a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8]];

           

           

          Why do you skip the first element of the CV array here:

           

             for (i=1; i<CV.length; i++) {

          • 2. Re: for (i=1; i<CV.length; i++) {
            Ron Colmen Level 2

            1. a[1], a[2] are data loaded from a MYSQL db.

             

            receiveLoad.onData = function(src) {

               var a:Array=src.split(",,");

             

             

            2. Sorry, My mistake. It should be (i=0; i<CV.length; i++) {

            • 3. Re: for (i=1; i<CV.length; i++) {
              kglad Adobe Community Professional & MVP

              use trace(i+" "+CV[i])

               

              to find the first problematic CV element and then trace your a elements to see why the corresponding a element is undefined.

              • 4. Re: for (i=1; i<CV.length; i++) {
                Ron Colmen Level 2

                All shows as undefined. What's the cause? How to fix this?

                 

                0 undefined

                1 undefined

                2 undefined

                3 undefined

                • 5. Re: for (i=1; i<CV.length; i++) {
                  Ned Murphy Adobe Community Professional & MVP

                  trace a[1]. a[2], a[3].... just before you assign them into the CV array

                  • 6. Re: for (i=1; i<CV.length; i++) {
                    Ron Colmen Level 2

                    yes, the trace shows the results outside of the CV but not inside CV.

                    • 7. Re: for (i=1; i<CV.length; i++) {
                      Ned Murphy Adobe Community Professional & MVP

                      Since you are showing separate pieces of code, the problem might lie in way you integrate them.  Can you show all of the relevant code involved from the onData function and the assignment to the CV array as you have it written in your file, not separated into different chunks?

                      • 8. Re: for (i=1; i<CV.length; i++) {
                        kglad Adobe Community Professional & MVP

                        you made your array a local to your onData.  use:

                         

                         

                        var a:Array;

                        receiveLoad.onData = function(src) {

                           a=src.split(",,");

                        • 9. Re: for (i=1; i<CV.length; i++) {
                          Ned Murphy Adobe Community Professional & MVP

                          When I told you to trace the a{1}, etc I literally meant to trace them just before you assign them to the CV array, as in the line before.  Did you

                          do that, or did you do it in some other section of code?

                          • 10. Re: for (i=1; i<CV.length; i++) {
                            kglad Adobe Community Professional & MVP

                            here's the problem:

                             

                            receiveLoad.onData = function(src) {

                             

                               var a:Array=src.split(",,");

                             

                             

                             

                            here's the solution:

                             

                            var a:Array;

                             

                            receiveLoad.onData = function(src) {

                             

                               a=src.split(",,");

                            • 11. Re: for (i=1; i<CV.length; i++) {
                              Ned Murphy Adobe Community Professional & MVP

                              Yes, that could well be the case depending on where CV is being assigned, but why are you telling me?  I was doing fine trying to help Ron home in on what he did wrong.

                              • 12. Re: for (i=1; i<CV.length; i++) {
                                kglad Adobe Community Professional & MVP

                                because there's no longer a question about what's causing the problem.   there's only one thing that could cause all of CV to have undefined elements and a to ever have defined elements.

                                • 13. Re: for (i=1; i<CV.length; i++) {
                                  Ron Colmen Level 2

                                  Thanks Kglad! - Thanks Ned!

                                   

                                  This is my code. The answer may be simple but I'm sort of lost here.

                                   

                                  1. I'm loading 12 MONTHS

                                  2. Depending on the name of the month the color should change.

                                   

                                   

                                  var senderLoad:LoadVars = new LoadVars();

                                  var receiveLoad:LoadVars = new LoadVars();

                                  var a:Array;

                                  receiveLoad.onData = function(src) {

                                     a=src.split(",,");

                                     result1.text=a[0];

                                     result2.text=a[1];

                                  // upto

                                     result12.text=a[11];

                                   

                                  var CVal:Array = [A8, B8, C8, D8, E8, F8, G8]; // name of the mc where the color should change

                                  var mcN:Array = [a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8]]; // the names of the months

                                   

                                  for (i=0; i<mcN.length; i++) {

                                      CVal[i].ivar=i;

                                  colorchange = new Color(CVal[i]);{

                                  if (mcN[this.ivar]== "JANUARY"){

                                  colorchange.setRGB(0xFFFFFF);

                                  }

                                  if (mcN[this.ivar]== "FEBRUARY"){

                                  colorchange.setRGB(0x000000);

                                  }

                                  }

                                  • 14. Re: for (i=1; i<CV.length; i++) {
                                    kglad Adobe Community Professional & MVP

                                    so, you're first problem is solved, correct?  if so, ned will continue to help you.

                                     

                                    but i think he'll want to know the relationship among the CVal movieclips, months and colors?

                                    • 15. Re: for (i=1; i<CV.length; i++) {
                                      Ron Colmen Level 2

                                      I hope so...

                                       

                                      When the data loads; if the a[1] is JANUARY,  certain mcs should change its color accordingly.

                                       

                                      I've got 7 mcs in my fla - that's CVal.

                                      if a[1] is JANUARY then the A8 should chnage it's colour to FFFFFF. if a[2] is JANUARY then the B8 should chnage it's colour to FFFFFF. if a[3] is FEBRUARY then the C8 should chnage it's colour to 000000. if a[4] is JANUARY then the D8 should chnage it's colour to FFFFFF.....

                                      • 16. Re: for (i=1; i<CV.length; i++) {
                                        Ned Murphy Adobe Community Professional & MVP

                                        It can be hard to hit a moving target, and with the code you showed you're presenting one.  If that code reflects what you had previously, then declaring the variable "a" outside the function wouldn't fix the problem since the once-named CV array would have been in scope if it is also being defined and assigned in that function.  So the first question is whether or not you are tracing the values you expect in the newly named mcN array?

                                         

                                        The next question, or comment actually, regards what the unpartnered " { " is doing at the end of the following line...

                                         

                                            colorchange = new Color(CVal[i]);{

                                         

                                        The next wondering regards what you are doing between looping with " i ", assigning it to "cVal[i].ivar", and what you think "this.ivar" has for a value -- try tracing it, and then try using " i " instead

                                        • 17. Re: for (i=1; i<CV.length; i++) {
                                          Ron Colmen Level 2

                                          I see what you're trying to say. I'm actually trying to shorten my existing code using those arrays & loops. Below is my old code. This works perfectly - but I'm trying to shorten it.

                                           

                                          This is the code (This works without any problem)

                                          var senderLoad:LoadVars = new LoadVars();

                                          var receiveLoad:LoadVars = new LoadVars();

                                          receiveLoad.onData = function(src) {

                                             var a:Array=src.split(",,");

                                             result1.text=a[0];

                                             result2.text=a[1];

                                           

                                          //A8

                                          colorchange = new Color(A8);{

                                          if (a[2]== "JANUARY"){

                                          colorchange.setRGB(0x000000);

                                          }

                                          if (a[2]== "FEBRUARY"){

                                          colorchange.setRGB(0xFFFFFF);

                                          }

                                          // goes on with all 12 months

                                          }

                                           

                                          //B8

                                          colorchange = new Color(B8);{

                                          if (a[3]== "JANUARY"){

                                          colorchange.setRGB(0xFFFFFF);

                                          }

                                          if (a[3]== "FEBRUARY"){

                                          colorchange.setRGB(0x000000);

                                          }

                                          // goes on with all 12 months

                                          }

                                           

                                          //C8

                                          colorchange = new Color(C8);{

                                          if (a[4]== "JANUARY"){

                                          colorchange.setRGB(0xFFFFFF);

                                          }

                                          if (a[4]== "FEBRUARY"){

                                          colorchange.setRGB(0x000000);

                                          }

                                          // goes on with all 12 months

                                          }

                                           

                                          //D8

                                          • 18. Re: for (i=1; i<CV.length; i++) {
                                            Ron Colmen Level 2

                                            Can someone help. This is getting complicated...

                                            • 19. Re: for (i=1; i<CV.length; i++) {
                                              Ned Murphy Adobe Community Professional & MVP

                                              I was trying to help, but you didn't answer my questions.  You just posted an example of what you are trying to convert as if to say "do it for me".  If keith happens along and would like to do that for you, that's good for you I guess.

                                               

                                              As I see it, you say you already have a working version of the file, so you can use that, and that leaves you plenty of time to do what you really need to do... sort this out yourself and learn in the process of doing so.  I doubt there is anything in doing this that you shouldn't have already learned in the past couple of years that you've been getting help here.

                                              • 20. Re: for (i=1; i<CV.length; i++) {
                                                Ron Colmen Level 2

                                                I know Ned... I was just curious in moving it off my head.