Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Getting inside others XML nodes programmatically, based on a single known node

New Here ,
Jan 16, 2010 Jan 16, 2010

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(""); }

TOPICS
ActionScript
785
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jan 17, 2010 Jan 17, 2010

i don't understand your question but, i'm pretty sure that function is going to return 30 everytime it's called.

Translate
Community Expert ,
Jan 16, 2010 Jan 16, 2010

your code is unreadable and there's no code showing the xml file's structure.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 17, 2010 Jan 17, 2010

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+". &#9830;</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+". &#9830;</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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 17, 2010 Jan 17, 2010

sorry .. actionscript here:

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 17, 2010 Jan 17, 2010

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);

    }
}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 17, 2010 Jan 17, 2010

will it be associated with the maximum and min values? I need to assign the min and max values with their corresponding dates.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 17, 2010 Jan 17, 2010

you'll need to code for that.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 17, 2010 Jan 17, 2010

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;

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 17, 2010 Jan 17, 2010

i don't understand your question but, i'm pretty sure that function is going to return 30 everytime it's called.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 17, 2010 Jan 17, 2010

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 17, 2010 Jan 17, 2010
LATEST

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;

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines