dcsimg
A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: Any tips on this?

  1. #1
    Member
    Join Date
    Sep 2014
    Posts
    77

    Any tips on this?

    Hello All,

    I have written this function:

    PHP Code:
    xd = [4815241561167];
    yd = [2267666];
    var 
    space = new Array();
    space prepare_Space_Array(xd);
    //
    for (var 0i<=xd.length-1i++) {
        
    trace(xd[i]+space[i]+yd[i]);
    }
    //
    function prepare_Space_Array(passedArray:Array) {
        
    //
        //the output is an array (spaceArray) contains space/separator.
        //
        
    var array_Contains_Length_passedArray_Elements:Array = new Array();
        var 
    diffSpace = new Array();
        var 
    spaceArray = new Array();
        var 
    longestSpace:Number 0;
        var 
    generalSpace:String "          ";
        
    //
        
    for (var 0i<=passedArray.length-1i++) {
            
    array_Contains_Length_passedArray_Elements.push(String(passedArray[i]).length);
            if (
    String(passedArray[i]).length>=longestSpace) {
                
    longestSpace String(passedArray[i]).length;
            }
        }
        
    //
        
    for (var 0i<=passedArray.length-1i++) {
            
    diffSpace.push(longestSpace-array_Contains_Length_passedArray_Elements[i]);
        }
        
    trace(diffSpace);
        
    //
        
    for (var 0i<=diffSpace.length-1i++) {
            var 
    space:String " ";
            for (var 
    0j<=diffSpace[i]; j++) {
                
    space " "+space;
            }
            
    space space+generalSpace;
            
    spaceArray.push(space);
        }
        
    //
        
    return spaceArray;
        
    //

    It is all about printing out data as two columns, the column on the right is left-aligned. What I mean here is that the printed data will be as following in the trace window:
    PHP Code:
    48                    226
    1524156116            7
    7                     666 
    As intended to be. However, when copy-&-paste or writing (using other software) this output in a text file it become as the following:
    PHP Code:
    48                            226
    1524156116               7
    7                             666 
    Any tips to follow? Thanks!
    Last edited by Dr_flash; 01-08-2016 at 09:29 AM.

  2. #2
    Member Alloy Bacon's Avatar
    Join Date
    Apr 2011
    Posts
    1,029
    I tried to use your code, but your script crashed my flash its so nested, can I attempt all different code that does the same thing?

  3. #3
    Member
    Join Date
    Sep 2014
    Posts
    77
    Quote Originally Posted by Alloy Bacon View Post
    I tried to use your code, but your script crashed my flash its so nested, can I attempt all different code that does the same thing?
    Hello Alloy,

    If you can come up with different code do the same purpose no problem.

    Thanks!

  4. #4
    Senior Member
    Join Date
    Aug 2012
    Posts
    124
    i test your file, it work ok all ways, even when copy paste to text file, if that what you mean,

    you can try use "\t" code for indent

    PHP Code:
    xd = [4815241561167];
    yd = [2267666];
    var 
    space = new Array();
    space prepare_Space_Array(xd);
    //
    for (var 0<= xd.length 1i++)
    {
        
    trace(xd[i] + space[i] + yd[i]);
    }
    //
    function prepare_Space_Array(passedArray:Array)
    {
        
    //
        //the output is an array (spaceArray) contains space/separator.
        //
        
    var array_Contains_Length_passedArray_Elements:Array = new Array();
        var 
    diffSpace = new Array();
        var 
    spaceArray = new Array();
        var 
    longestSpace:Number 0;
        var 
    generalSpace:String "\t";
        
    //
        
    for (var 0<= passedArray.length 1i++)
        {
            
    array_Contains_Length_passedArray_Elements.push(String(passedArray[i]).length);
            if (
    String(passedArray[i]).length >= longestSpace)
            {
                
    longestSpace String(passedArray[i]).length;
            }
        }
        
    //
        
    for (var 0<= passedArray.length 1i++)
        {
            
    diffSpace.push(longestSpace array_Contains_Length_passedArray_Elements[i]);
        }
        
    trace(diffSpace);
        
    //
        
    for (var 0<= diffSpace.length 1i++)
        {
            var 
    space:String "\t";
            for (var 
    0<= diffSpace[i]; j++)
            {
                
    space " " space;
            }
            
    space space generalSpace;
            
    spaceArray.push(space);
        }
        
    //
        
    return spaceArray;
        
    //


  5. #5
    Member
    Join Date
    Sep 2014
    Posts
    77
    Thank you Terrecing!

  6. #6
    Senior Member
    Join Date
    Aug 2012
    Posts
    124
    good, i not look too long through it, but it was a little mixed up and can be tighter.
    not no why alloy say he crash flash trying it, straight forward function really.

    PHP Code:
    var xd:Array = [4815241561167345434534534543534534];
    var 
    yd:Array = [22676666767671675675674675673375686756];

    var 
    igj:Number;
    var 
    spacer:String "\t\t\t";

    var 
    space:Array = new Array();
    space doSpaces(xd);

    for (var 
    0xd.lengthi++)
    {
        
    trace(xd[i] + spacer yd[i]);
    }

    function 
    doSpaces(arg:Array)
    {
        var 
    gaps:Array = new Array();
        var 
    difference:Array = new Array();
        var 
    longest:Number 0;

        for (
    0arg.lengthi++)
        {
            
    gaps.push(String(arg[i]).length);

            if (
    String(arg[i]).length >= longest)
            {
                
    longest String(arg[i]).length;
            }
        }

        for (
    0arg.lengthi++)
        {
            
    difference.push(longest gaps[i]);
        }

        
    trace("Longest string length: " longest);
        
    trace("String lengths: " gaps);
        
    trace("Differences from longest: " difference);
        
    trace("----------------------");

        for (
    0difference.lengthi++)
        {
            for (
    0difference[i]; j++)
            {
                
    difference[i];
                if (
    0)
                {
                    
    xd[i] += ".";// swap "." for " "
                
    }
                else
                {
                    
    xd[i] = xd[i];
                }
            }
        }

    no need to do i (i <= array.kength -1 ) all time, same as (i < array.length )

  7. #7
    Member
    Join Date
    Sep 2014
    Posts
    77
    Quote Originally Posted by Terrencing View Post
    good, i not look too long through it, but it was a little mixed up and can be tighter.
    not no why alloy say he crash flash trying it, straight forward function really.
    Thanks again Terrecing, Really great of you. Trying the code now!!!

    Quote Originally Posted by Terrencing View Post
    no need to do i (i <= array.kength -1 ) all time, same as (i < array.length )
    I know they are the same . When I have started coding in AS1.0 & 2.0 I learned it like (i <= array.kength -1 ), so when I am coding it just comes like that, I can't help it!

    Regards!
    Last edited by Dr_flash; 01-11-2016 at 02:00 PM.

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