Copy link to clipboard
Copied
Hi guys, I have an array being generated with numbers from an XML file. Then I have the function 'maxF' that returns the maximum number inside that array. I need to get programaticaly other nodes inside the same XML file [where all these numbers are coming from] to print the date [which is a node on top of the number node]. Does anyone out there can please help me do that?
Thank you very much
var a:Array = []; for (var i = 1; i<=15; i++) { var RootNode = getXml.firstChild; eval("price"+i).htmlText = "<p class='price'>"+RootNode.childNodes.childNodes[4].childNodes[2].firstChild+"</p>"; eval("price"+i+15).htmlText = "<p class='price'>"+RootNode.childNodes[i+15].childNodes[4].childNodes[2].firstChild+"</p>"; //trace(stripF(RootNode.childNodes[i+15].childNodes[4].childNodes[2].firstChild.nodeValue)); a.push(Number(stripF(tl["price"+i].text))); a.push(Number(stripF(tl["price"+i+15].text))); } lowestup.htmlText = "<p class='lowprice'>"+maxF(a)+"</p>"; lowestPeriodTitle.htmlText = "<p class='regular' align='center'>OPTIMAL VALUES IDENTIFIED:</p>";
function maxF(a:Array):Number { var max:Number = a[0]; for (var i:Number = 1; i>a.length; i++) { if (a>min) { max = a; } else { //trace("buahMin!"); } } return max; } function stripF(s:String):String { return s.split(" ").join("").split("\n").join("").split("\r").join(""); }
1 Correct answer
i don't understand your question but, i'm pretty sure that function is going to return 30 everytime it's called.
Copy link to clipboard
Copied
your code is unreadable and there's no code showing the xml file's structure.
Copy link to clipboard
Copied
This is the actionscript:
//creating txtfield var tl:MovieClip = this; //var colnum:Number = 2; var txtX:Number = -100; var txtY:Number = -65; var txtWdth = 50; var txtHgt = 16; for (var i = 1; i<=15; i++) { tl.createTextField("day"+i,tl.getNextHighestDepth(),txtX,txtY,txtWdth,txtHgt); tl.createTextField("price"+i,tl.getNextHighestDepth(),txtX+47,txtY,txtWdth,txtHgt); tl.createTextField("day"+i+15,tl.getNextHighestDepth(),txtX+115,txtY,txtWdth,txtHgt); tl.createTextField("price"+i+15,tl.getNextHighestDepth(),txtX+163,txtY,txtWdth,txtHgt); tl["day"+i].html = true; tl["price"+i].html = true; tl["day"+i+15].html = true; tl["price"+i+15].html = true; txtY += 17; } tl.createTextField("day6",tl.getNextHighestDepth(),txtX,20,txtWdth,txtHgt); tl.createTextField("price2",tl.getNextHighestDepth(),txtX+47,-48,txtWdth,txtHgt); tl.createTextField("lowestPeriodTitle",tl.getNextHighestDepth(),-98,-150,235,55); tl.createTextField("lowestup",tl.getNextHighestDepth(),-90,-135,150,30); tl.createTextField("lowestdown",tl.getNextHighestDepth(),-90,-115,150,30); tl.createTextField("moeda",tl.getNextHighestDepth(),-90,-65,100,16); tl.createTextField("currencyName",tl.getNextHighestDepth(),40,-200,100,16); tl.createTextField("currencyDate",tl.getNextHighestDepth(),40,-190,100,60); tl.createTextField("currentPrice",20,-90,-205,235,55); currencyName.html = true; currencyDate.html = true; currencyDate.multiline = true; currentPrice.html = true; resultsField.html = true; lowestup.html = true; lowestdown.html = true; lowestPeriodTitle.html = true;
//CSS Handler var getXml = new XML(); var stylish = new TextField.StyleSheet(); stylish.load("coreasset/currency.css"); stylish.onLoad = function(success:Boolean) { if (success) { //trace("cssLoaded!"); for (var i = 1; i<=15; i++) { tl["price"+i].styleSheet = stylish; tl["day"+i].styleSheet = stylish; tl["price"+i+15].styleSheet = stylish; tl["day"+i+15].styleSheet = stylish; } tl.lowestPeriodTitle.styleSheet = stylish; tl.lowestup.styleSheet = stylish; tl.lowestdown.styleSheet = stylish; tl.moeda.styleSheet = stylish; tl.currencyName.styleSheet = stylish; tl.currencyDate.styleSheet = stylish; tl.currentPrice.styleSheet = stylish; getXml.load("coreasset/eur.xml"); } }; getXml.ignoreWhite = true; //loading XML into Dinamic fields getXml.onLoad = function(success) { if (success) { var a:Array = []; for (var i = 1; i<=15; i++) { var RootNode = getXml.firstChild; var currency = "<p class='headsup'>"+RootNode.childNodes[i+16].childNodes[1].firstChild+"</p>"; var currencyusd = "<p class='headsup'>"+RootNode.childNodes[i+16].childNodes[0].firstChild+"</p>"; eval("day"+i).htmlText = "<p class='date'>"+RootNode.childNodes.childNodes[4].firstChild.firstChild+". ♦</p>"; eval("price"+i).htmlText = "<p class='price'>"+RootNode.childNodes.childNodes[4].childNodes[2].firstChild+"</p>"; eval("day"+i+15).htmlText = "<p class='date'>"+RootNode.childNodes[i+15].childNodes[4].firstChild.firstChild+". ♦</p>"; eval("price"+i+15).htmlText = "<p class='price'>"+RootNode.childNodes[i+15].childNodes[4].childNodes[2].firstChild+"</p>"; currentPrice.htmlText = "<p class='bigPrice'>"+RootNode.childNodes[i+16].childNodes[4].childNodes[2].firstChild+"</p>"; currencyName.htmlText = "<p class='currencyName'><b>"+currencyusd+currency+"</b></p>"; currencyDate.htmlText = "<a class='headsup'>Fictitious date:<br>"+RootNode.childNodes[i+16].childNodes[4].firstChild.firstChild+". 2010</a>"; //trace(RootNode.firstChild.childNodes[4].childNodes[1].firstChild); //trace(stripF(RootNode.childNodes[i+15].childNodes[4].childNodes[2].firstChild.nodeValue)); a.push(Number(stripF(tl["price"+i].text))); a.push(Number(stripF(tl["price"+i+15].text))); } lowestup.htmlText = "<p class='lowprice'>"+maxF(a)+"</p>"; lowestdown.htmlText = "<p class='lowprice'>"+minF(a)+"</p>"; lowestPeriodTitle.htmlText = "<p class='regular' align='center'>OPTIMAL VALUES IDENTIFIED:</p>"; } else { trace("buahCol!"); } }; function minF(a:Array):Number { var min:Number = a[0]; for (var i:Number = 1; i<a.length; i++) { if (a<min) { min = a; } else { //trace("buahMin!"); } } return min; } function maxF(a:Array):Number { var max:Number = a[0]; for (var i:Number = 1; i>a.length; i++) { if (a>max) { max = a; } else { //trace("buahMin!"); } } return max; trace(a); } function stripF(s:String):String { return s.split(" ").join("").split("\n").join("").split("\r").join(""); } function maxDate() { for (var i:Number = 1; i<30; i++) { { if (lowestup.htmlText == eval("price"+i).htmlText) { trace(i); } else { trace("date"); } } }; return i; } tl.createTextField("teste",tl.getNextHighestDepth(),40,-290,100,16); teste.text = maxDate(); /* Inside the XML file --- hahahahahhaha RootNode.firstChild.childNodes[4].firstChild.firstChild ---- response/days/conversion/date RootNode.firstChild.childNodes[4].childNodes[2].firstChild ---- response/days/conversion/bid */
The xml is attached to this msg.
If you see the actionscript, there is a function called 'maxDate', where I am trying to find out the textField name ['price' + i] that contains the max and minimum, then I thought of applying the same 'i' in the 'day' name, this was one way I was thinking on retrieving the date that corresponds to that maximum and minimun value. But for some reason it is not working.
do you have a better suggestion on how to get the date that those values [min and max] are related to?
Thank you very much.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
the following will store your dates in an array:
var datesA:Array
var xml:XML = new XML();
xml.onLoad = parseXML;
xml.ignoreWhite = true;
xml.load("eur.xml");
function parseXML() {
datesA = []
for (var i:Number = 0; i<this.firstChild.childNodes.length; i++) {
var xmlNode:XMLNode = this.firstChild.childNodes;
datesA.push(xmlNode.childNodes[4].childNodes[0].firstChild.nodeValue);
}
}
Copy link to clipboard
Copied
will it be associated with the maximum and min values? I need to assign the min and max values with their corresponding dates.
Copy link to clipboard
Copied
you'll need to code for that.
Copy link to clipboard
Copied
Thanks. I will try to figure it out. --:]
Don't you think this way would it be easier? Finding out the name of the price field than applying the same 'i' to the day textField?
function maxDate() {
for (var i:Number = 1; i<30; i++) {
{
if (lowestup.htmlText == eval("price"+i).htmlText) {
trace(i);
} else {
//trace("date");
}
}
};
return i;
}
Copy link to clipboard
Copied
i don't understand your question but, i'm pretty sure that function is going to return 30 everytime it's called.
Copy link to clipboard
Copied
thank you. I was trying to find out with the function which is the "i" of the price+i field that corresponds to the max and min value.
Copy link to clipboard
Copied
then you can use findTF() where you pass the string you're trying to match:
function findTF(s:String):Number {
for (var i:Number = 1; i<30; i++) {
if (s == this["price"+i].text) {
return i
}
}
return -1;
}

