make several arrays from one array
A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: make several arrays from one array

  1. #1
    Member
    Join Date
    Aug 2012
    Posts
    53

    make several arrays from one array

    Hello,

    I need to be able to split my array into several arrays.

    so far I have
    PHP Code:
    var Speech:Array = ["abcde""abcde""abcde""abcde""abcde""abcde""abcde""abcde""abcde""abcde""abcde"];
    var 
    Amount:Number Speech.length;// 11 at present
    var Clipped:Number 3
    the original array length does change, get longer over time, i always want the same divide.

    clipped is the amount of arrays i want to split the array into( or any other number should i change it)

    looking for this
    PHP Code:
    new array = (["abcde","abcde","abcde","abcde"],["abcde","abcde","abcde","abcde"],["abcde","abcde","abcde"]) 
    I have absolutely no idea,

    may thanks for looking
    Last edited by Terrencing; 04-23-2013 at 10:22 AM.

  2. #2
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,106
    Hi,

    This is something I hacked together, perhaps it can be jiggled around a bit for better coding ???

    try it and see what it traces for you.
    PHP Code:
    var = ["abcde""abcde""abcde""abcde""abcde""abcde""abcde""abcde""abcde""abcde""abcde"];
    var 
    J:Number A.length;
    var 
    NewArray:Array = [];
    var 
    MySplit:Number 3;
    var 
    S:Number 0;
    var 
    i:Number;

    trace("// Original array started as [" "]");
    trace("// Original array length = " J);
    trace("// Split original array into arrays " MySplit " parts long,");
    trace("// then create single end array with extra (if any).");
    for (
    0Ji++)
    {
        
    NewArray[i] = [];
        if (
    A.length MySplit)
        {
            if (
    A.length 1)
            {
                break;
            }
            else
            {
                
    CC A.splice(0A.length);
                
    NewArray[i].push(CC);
                
    trace("NewArray[[" "]]=[" NewArray[i] + "]" " Array length = " NewArray[i][0].length);
                
    S++;
                break;
            }
        }
        else
        {
            
    CC A.splice(0MySplit);
            
    NewArray[i].push(CC);
            
    trace("NewArray[[" "]]=[" NewArray[i] + "]" " Array length = " NewArray[i][0].length);
            
    S++;
        }
    }
    trace("// " " separate arrays have now been created from the original and merged.");
    trace("// Original array finished as [" "]"); 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width


HTML5 Development Center

Poll by Flashkit.com