9 Replies Latest reply on Jan 3, 2011 1:39 PM by Fayena

    help! inconsistent output

    Fayena

      I know where this is happening its in this function:

       

      function percent(foalObj:Array,perX:Number):Array{

           trace("break");

           for (var b:String in foalObj) {

                trace(b + ":" + foalObj[b]);

                }

           for (var i:String in foalObj) {

                var perEach:Number = perX * foalObj[i];

                foalObj[i] = perEach;

       

                 }//end for

           trace ("break");

           for (var c:String in foalObj) {

                trace(c + ":" + foalObj[c]);}

           return foalObj;

      }//end fucntion

       

      I'm changing as few variables as possible but sometimes I get a good output and sometimes I don't. 

       

      For example in testing I'm changing one input and keeping everything else the same.  I open up a the .swf fresh for each test run and I've even tried recompiling it with no success. 

       

      here are the changing inputs. If there is nothing beside it the input the output was good, the bad outputs are marked.

       

      1st run

      EeAtAt

      EeAa

      EeAA:  Bad

      EeAa

       

      2nd run

      EeAtAt

      EeAa

      EeAA

      Eeaa

      EeAtAt

      EeAta:  Bad

       

      3rd run

      EeAtAt:Bad

      EeAa

      EeAA:Bad

      EeAa

      EeAta: Bad

      Eeaa:bad

      EeAa

       

      4th run

      EeAAt

      EeAtAt

      EeAta

      Eeaa

      EeAA

      EeAAt Bad

       

      5th run

      EeAa

      EeAAt: Bad

       

      6th run

      EeAAt

      EeAAt

      EeAtAt

      EeAa

      EeAa

      EeAAt

      EeAA Bad

       

      The actual tracings look like this for a good one

      break

      EE,AA:1

      Ee,Aa:4

      ee,aa:1

      Ee,aa:2

      ee,AA:1

      EE,Aa:2

      EE,aa:1

      ee,Aa:2

      Ee,AA:2

      break

      EE,AA:5.40625

      Ee,Aa:21.625

      ee,aa:5.40625

      Ee,aa:10.8125

      ee,AA:5.40625

      EE,Aa:10.8125

      EE,aa:5.40625

      ee,Aa:10.8125

      Ee,AA:10.8125

      break

      And this for a bad one.
      break
      ee,Aa:2
      ee,AA:2
      EE,Aa:2
      EE,AA:2
      Ee,Aa:4
      Ee,AA:4
      break
      EE,AA:10.8125
      ee,Aa:58.455078125
      ee,AA:10.8125
      EE,Aa:10.8125
      Ee,Aa:21.625
      Ee,AA:21.625
      break
      I'm at a loss as to what is going on and what I need to do to fix it.  Suggestions would be very much appreciated.

        • 1. Re: help! inconsistent output
          saisri2k2 Level 4

          what are you trying to do here with this 'foalObj[b]' statement in the for loop? you re passing array[somebject] which is wrong? it should be array[someNumber]

          • 2. Re: help! inconsistent output
            Fayena Level 1

            Note that the key named aspect ratio contains a space character. This is possible with the bracket operator, but generates an error if attempted with the dot operator. Using spaces in your key names is not recommended.

            The second way to create an associative array is to use the Array constructor (or the constructor of any dynamic class) and then use either the bracket operator ([]) or the dot operator (.) to add key and value pairs to the array. If you declare your associative array to be of type Array, you cannot use an object literal to initialize the array. The following example creates an associative array named monitorInfo using the Array constructor and adds a key called type and a key called resolution, along with their values:

            var monitorInfo:Array = new Array();
            monitorInfo["type"] = "Flat Panel";
            monitorInfo["resolution"] = "1600 x 1200";
            trace(monitorInfo["type"], monitorInfo["resolution"]); 
            // output: Flat Panel 1600 x 1200
            
            

            There is no advantage in using the Array constructor to create an associative array. You cannot use the Array.length property or any of the methods of the Array class with associative arrays, even if you use the Array constructor or the Array data type. The use of the Array constructor is best left for the creation of indexed arrays.

             

            I did find this in the docs.  So technically it "should" work but probably isn't best practices.  I'll change them to objects and see if it makes a difference. 

            • 3. Re: help! inconsistent output
              Fayena Level 1

              I changed all the associative arrays to Objects with no results.   If you need more info please just let me know.  I really want to figure out what is happening.  If its something stupid I'm missing please don't hesitate to point it out to me.    

              • 4. Re: help! inconsistent output
                saisri2k2 Level 4

                why not use hash map? code below. I think it will be helpful in your case.

                 

                I'm guessing from the code you have mentioned that you need key-value pair to be stored in an array rite? wthout non repetitive keys?

                 

                http://www.ericfeminella.com/blog/2006/12/05/as3-hashmap-for-flex/

                 

                Message was edited by: saisri2k2

                • 5. Re: help! inconsistent output
                  Fayena Level 1

                  I had to read a bit on hash maps and itsn't that pretty much what I already have?  What would be the advantages of using the code you suggested vs what I have now (object with string keys)  vs trying to implement a dictionary class as suggested here http://insideria.com/2008/04/dictionaries-and-associative-a.html

                   

                  Even with all that, I'm still left wondering what is causing this problem in the first place.  

                   

                   

                  Edit:  Just wanted to add that I tried changing all the Objects to Dictionaries and that didn't help either

                  • 6. Re: help! inconsistent output
                    Fayena Level 1

                    I've been looking at this to long....Had to delete a whole post cause I was being stupid.   Here is the function again I've got a trace right off the back to track the input which turns out to be correct.  The problem is creeping in during the second for loop and trace.  What the heck is going on?????  Please keep in mind this doesn't happen every time I run the swf.  It is happening randomly as far as I can tell. 

                     

                     

                    function percent(foalObj:Object,perX:Number):Object{
                         for (var p:String in foalObj) {
                              trace("The very line in percent"+p + ":" + foalObj[p]);}
                          for (var i:String in foalObj) {
                              trace(i + ":" + foalObj[i]);
                              trace("perX:"+perX);
                              trace("perX*FoalObj[i]:" + perX * foalObj[i]);
                              //perEach = perX * foalObj[i];
                              //foalObj[i] = perEach;
                              foalObj[i] = perX * foalObj[i];
                              trace("after calculation["+i+"]:" + foalObj[i]);
                              }//end for
                         return foalObj;
                    }//end function

                     

                     

                    This input is correct:

                    The very first input in percent ee,AtA:2

                    The very first input in percent ee,Ata:2

                    The very first input in percent EE,Ata:2

                    The very first input in percent Ee,Ata:4

                    The very first input in percent EE,AtA:2

                    The very first input in percent Ee,AtA:4

                     

                     

                    ee,AtA:2

                    perX:5.40625

                    perX*FoalObj[i]:10.8125

                    after calculation[ee,AtA]:10.8125

                     

                    EE,Ata:2

                    perX:5.40625

                    perX*FoalObj[i]:10.8125

                    after calculation[EE,Ata]:10.8125

                     

                    ee,AtA:10.8125  <--Here is the problem this should be eeAta

                    perX:5.40625

                    perX*FoalObj[i]:58.455078125

                    after calculation[ee,AtA]:58.455078125

                     

                    Ee,AtA:4

                    perX:5.40625

                    perX*FoalObj[i]:21.625

                    after calculation[Ee,AtA]:21.625

                     

                    ee,Ata:2

                    perX:5.40625

                    perX*FoalObj[i]:10.8125

                    after calculation[ee,Ata]:10.8125

                     

                    Ee,Ata:4

                    perX:5.40625

                    perX*FoalObj[i]:21.625

                    after calculation[Ee,Ata]:21.625

                     

                    EE,AtA:2

                    perX:5.40625

                    perX*FoalObj[i]:10.8125

                    after calculation[EE,AtA]:10.8125

                    • 7. Re: help! inconsistent output
                      Fayena Level 1

                      Does anyone have any idea? 

                      • 8. Re: help! inconsistent output
                        saisri2k2 Level 4

                        I would suggest you to use flash debugger to debug this issue, this one is involving a lot of references i guess, please watch each and everly element in the whole process..

                        • 9. Re: help! inconsistent output
                          Fayena Level 1

                          I'm using the debugger as well I know how and its showing me the same thing the trace outputs are.  I uploaded the swf to my website so you can at least see the inputs and outputs.  Maybe one of you can see a pattern I'm missing.  When I'm testing this I'm only changing the input for agouti.   It doesn't matter if you change sire or dam they will both eventually give an erroneous result.

                           

                          http://www.equine-color.info/calc/FlashCalc/colorcalc.html

                           

                          Forgot to add:  please don't laugh at the interface I know it is REALLY ugly.