Array maddness programmer on the verge of a breakdown

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Zarwadi
    New Member
    • Jun 2007
    • 34

    Array maddness programmer on the verge of a breakdown

    Ok I hope someone can help me. My first array looks like this
    array1 = (Section A, Section E,undefined,und efined,undefine d,undefined,und efined,undefine d)
    and my second 1 looks like this array 2 =( Section A, Section B, Section C, Section D, Section E,2. GRCM,3. ASPEN,4. R1)

    I need to place Section A in my first array in position [0] and in position [4]. Can this be done by using the information from the second array. Please please can sonebody help me
  • rsdev
    New Member
    • Jul 2007
    • 149

    #2
    Originally posted by Zarwadi
    Ok I hope someone can help me. My first array looks like this
    array1 = (Section A, Section E,undefined,und efined,undefine d,undefined,und efined,undefine d)
    and my second 1 looks like this array 2 =( Section A, Section B, Section C, Section D, Section E,2. GRCM,3. ASPEN,4. R1)

    I need to place Section A in my first array in position [0] and in position [4]. Can this be done by using the information from the second array. Please please can sonebody help me
    Is this in AS Flash?

    Comment

    • Zarwadi
      New Member
      • Jun 2007
      • 34

      #3
      Originally posted by rsdev
      Is this in AS Flash?
      Yes it is as flash file. ireall hope you can help me
      Zar

      Comment

      • rsdev
        New Member
        • Jul 2007
        • 149

        #4
        Not sure what your trying to acheive but if you use Array.splice you can insert values into an array at a given position.

        Take a look here for more info.

        http://www.adobe.com/support/flash/action_scripts/actionscript_di ctionary/actionscript_di ctionary070.htm l

        Hope this helps!

        Comment

        • Zarwadi
          New Member
          • Jun 2007
          • 34

          #5
          Thanks for that but I know it does not do what I want.
          I have not explained myself properly.
          I's like this I have one array that looks like this
          (Section D,Section A,undefined,und efined,undefine d,undefined,und efined,undefine d)

          and another array looks like this (Section A,Section B,Section C,Section D,Section E,2. GRCM,3. ASPEN,4. R1)

          I need to find where Section D and Section A are in the second array. ie Section A = 0 and Section D = 3
          I hope this makes sense

          Comment

          • rsdev
            New Member
            • Jul 2007
            • 149

            #6
            Are you trying to make a recursive method that uses the values in the first array to find the position of values in the second array?

            Here is an example model of the top of my head (untested);

            Code:
            var array3:Array = new Array();
            var t;
            for(var i=0; i<array1.length; i++){
                t = firstArray(array1, array2)
                if(t>0){
                     array3.push(t);
                }
            }
            
            function firstArray(array1:Array, array2:Array):Number{
                  var l = array1.length;
                  for(var i=0; i<l; i++){
                      if(array1[i] == secondArray(array2, array1[i])){
                           return i;
                      } else {
                            return 0;
                      }
                   }
            }
            
            function secondArray(array2:Array, arrayObject:Object):Object{
                 var l = array2.length;
                 for(var i=0; i<l; i++){
                       if(array2[i] == arrayObject){
                            return array2[i];
                       }
                 }
            }
            Not sure if this will work but should get you started.

            Comment

            • Zarwadi
              New Member
              • Jun 2007
              • 34

              #7
              Thanks
              for your help

              Originally posted by rsdev
              Are you trying to make a recursive method that uses the values in the first array to find the position of values in the second array?

              Here is an example model of the top of my head (untested);

              Code:
              var array3:Array = new Array();
              var t;
              for(var i=0; i<array1.length; i++){
                  t = firstArray(array1, array2)
                  if(t>0){
                       array3.push(t);
                  }
              }
              
              function firstArray(array1:Array, array2:Array):Number{
                    var l = array1.length;
                    for(var i=0; i<l; i++){
                        if(array1[i] == secondArray(array2, array1[i])){
                             return i;
                        } else {
                              return 0;
                        }
                     }
              }
              
              function secondArray(array2:Array, arrayObject:Object):Object{
                   var l = array2.length;
                   for(var i=0; i<l; i++){
                         if(array2[i] == arrayObject){
                              return array2[i];
                         }
                   }
              }
              Not sure if this will work but should get you started.

              Comment

              Working...