-
Parsing XML data for calculations and then output number with commas
I have a project for class that loads xml data then outputs in bar chart format. Once the data is loaded and the bar value is calculated I would like to show the numbers with commas ie any number over 999, 9999 etc. I have tried a few things but nothing seems to work.
Here is my array set up and xml load;
function createLabels(arr:Array):Void {
var LabelHolder:MovieClip = _root.createEmptyMovieClip("LabelHolder", _root.getNextHighestDepth());
for (var i:Number = 0; i<arr.length; i++) {
var mm:MovieClip = LabelHolder.createEmptyMovieClip("mm"+i, LabelHolder.getNextHighestDepth());
mm._y = -45;
var tf:TextField = mm.createTextField("TT", mm.getNextHighestDepth(), 0, 1, 0, 0);
tf.autoSize = true;
tf.selectable = false;
tf.multiline = false;
tf.text = arr[i].title;
tf.setTextFormat(fmt);
}
updateFilter(LabelHolder, 1, 2)
}
var valueArr:Array;
var fmt:TextFormat = new TextFormat();
fmt.align = left;
fmt.color = 0x000000;
fmt.font = "Arial";
fmt.size = 10;
fmt.bold = true;
var graphXml:XML = new XML();
graphXml.load(_root.xml_path);
graphXml.ignoreWhite = true;
graphXml.onLoad = function(success) {
if (success) {
var graphArray:Array = this.firstChild.childNodes;
calculate(graphArray);
} else {
trace("No XML Found");
}
};
function calculate(arr:Array):Void {
valueArr = new Array();
for (var i = 0; i<arr.length; i++) {
var obj:Object = new Object();
obj.title = arr[i].childNodes[0].firstChild.nodeValue;
obj.color = arr[i].childNodes[1].firstChild.nodeValue;
obj.percent = arr[i].childNodes[2].firstChild.nodeValue;
valueArr.push(obj);
}
Here is where I output the data as text;
var p_tf:TextField = bar.createTextField("PerText", 0, 0, 7, 0, 0);
p_tf.autoSize = true;
p_tf.selectable = false;
p_tf.multiline = false;
p_tf.text = arr[no].percent+"";
p_tf.setTextFormat(fmt);
in the second to last line I have accounted for numbers that need a trailing % sign
Thanks Adam
Last edited by AVaughn; 09-17-2010 at 08:22 AM.
-
Senior Member
could it be as simple as taking the string in the textBox..
(are these dollars? ie: the 000.00 format? cents?)
if yes..then do a check to see if the there is a period in charAt(string.length-2);
if not..then just take the string.. and count backwards in 3's adding comments.
string.length/3 = how many commas you'll use..
then use that as your loop counter.
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
|