-
Any tips on this?
Hello All,
I have written this function:
PHP Code:
xd = [48, 1524156116, 7]; yd = [226, 7, 666]; var space = new Array(); space = prepare_Space_Array(xd); // for (var i = 0; i<=xd.length-1; i++) { 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 i = 0; i<=passedArray.length-1; i++) { array_Contains_Length_passedArray_Elements.push(String(passedArray[i]).length); if (String(passedArray[i]).length>=longestSpace) { longestSpace = String(passedArray[i]).length; } } // for (var i = 0; i<=passedArray.length-1; i++) { diffSpace.push(longestSpace-array_Contains_Length_passedArray_Elements[i]); } trace(diffSpace); // for (var i = 0; i<=diffSpace.length-1; i++) { var space:String = " "; for (var j = 0; j<=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.
-
Client Software Programmer
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?
-
Originally Posted by Alloy Bacon
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!
-
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 = [48, 1524156116, 7]; yd = [226, 7, 666]; var space = new Array(); space = prepare_Space_Array(xd); // for (var i = 0; i <= xd.length - 1; i++) { 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 i = 0; i <= passedArray.length - 1; i++) { array_Contains_Length_passedArray_Elements.push(String(passedArray[i]).length); if (String(passedArray[i]).length >= longestSpace) { longestSpace = String(passedArray[i]).length; } } // for (var i = 0; i <= passedArray.length - 1; i++) { diffSpace.push(longestSpace - array_Contains_Length_passedArray_Elements[i]); } trace(diffSpace); // for (var i = 0; i <= diffSpace.length - 1; i++) { var space:String = "\t"; for (var j = 0; j <= diffSpace[i]; j++) { space = " " + space; } space = space + generalSpace; spaceArray.push(space); } // return spaceArray; // }
-
-
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 = [48, 1524156116, 73454, 345, 345, 34, 543, 534, 534];
var yd:Array = [226, 7, 666, 67, 6767, 167567567, 467567, 33756, 86756];
var i, g, j:Number;
var spacer:String = "\t\t\t";
var space:Array = new Array();
space = doSpaces(xd);
for (var i = 0; i < xd.length; i++)
{
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 (i = 0; i < arg.length; i++)
{
gaps.push(String(arg[i]).length);
if (String(arg[i]).length >= longest)
{
longest = String(arg[i]).length;
}
}
for (i = 0; i < arg.length; i++)
{
difference.push(longest - gaps[i]);
}
trace("Longest string length: " + longest);
trace("String lengths: " + gaps);
trace("Differences from longest: " + difference);
trace("----------------------");
for (i = 0; i < difference.length; i++)
{
for (j = 0; j < difference[i]; j++)
{
g = difference[i];
if (g > 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 )
-
Originally Posted by Terrencing
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!!!
Originally Posted by Terrencing
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|