XML doesn't work in flash.

  • Thomper
  • Born
  • Born
  • No Avatar
  • Joined: Sep 11, 2008
  • Posts: 4
  • Status: Offline

Post September 16th, 2008, 5:38 am

Hello i am workin atm at a flash file that must extract xml data from a .xml file.
It works only it shows only the last one in the textfield.
How can i show the other ones to?
Here is the code:

Code: [ Select ]
controleID = setInterval(interval, 5000);
var myXML:XML = new XML();
myXML.ignoreWhite = true;
myXML.load("info.xml");
myXML.onLoad = function(success) {
    if (success) {
        var myImage = myXML.firstChild.childNodes;
        //var myTextField = ("tLabel" + i);
        for (i=0; i<myImage.length; i++) {
            var h = 40;
            var imageNumber = i+1;
            var old = 10;
            var imageName =         myImage[i].attributes.merk;
            var imagesdescription = myImage[i].attributes.sdescription;
            var imageldescription = myImage[i].attributes.ldescription;
            var imageprijs =     myImage[i].attributes.prijs;
            //Create Text Field
            createTextField("tLabel"+i,this.getNextHighestDepth(),10,i*h,400,old += 40);
            tLabel2.html = true;
            tLabel2.htmlText = imageName+" "+imagesdescription+" "+imageldescription+" "+imageprijs;
            tLabel2.setTextFormat(tfFormatter);
            trace(myImage[i]);
            //Text Format
            var tfFormatter:TextFormat = new TextFormat();
            tfFormatter.font = "Arial";
            tfFormatter.size = 14;
        }
    }
};
  1. controleID = setInterval(interval, 5000);
  2. var myXML:XML = new XML();
  3. myXML.ignoreWhite = true;
  4. myXML.load("info.xml");
  5. myXML.onLoad = function(success) {
  6.     if (success) {
  7.         var myImage = myXML.firstChild.childNodes;
  8.         //var myTextField = ("tLabel" + i);
  9.         for (i=0; i<myImage.length; i++) {
  10.             var h = 40;
  11.             var imageNumber = i+1;
  12.             var old = 10;
  13.             var imageName =         myImage[i].attributes.merk;
  14.             var imagesdescription = myImage[i].attributes.sdescription;
  15.             var imageldescription = myImage[i].attributes.ldescription;
  16.             var imageprijs =     myImage[i].attributes.prijs;
  17.             //Create Text Field
  18.             createTextField("tLabel"+i,this.getNextHighestDepth(),10,i*h,400,old += 40);
  19.             tLabel2.html = true;
  20.             tLabel2.htmlText = imageName+" "+imagesdescription+" "+imageldescription+" "+imageprijs;
  21.             tLabel2.setTextFormat(tfFormatter);
  22.             trace(myImage[i]);
  23.             //Text Format
  24.             var tfFormatter:TextFormat = new TextFormat();
  25.             tfFormatter.font = "Arial";
  26.             tfFormatter.size = 14;
  27.         }
  28.     }
  29. };
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post September 16th, 2008, 5:38 am

  • graphixboy
  • Control + Z
  • Mastermind
  • User avatar
  • Joined: Jul 11, 2005
  • Posts: 1828
  • Loc: In the Great White North
  • Status: Offline

Post September 16th, 2008, 12:04 pm

can you post your XML too? I think you have a malformed tag in your XML causing flash to ignore something.
If at first you don't succeed F1... If that doesn't work try Google!
//// Designer, Developer & Teacher - Interactive, Motion and 3D \\\\
Portfolio at WhenImNotSleeping.com
  • Thomper
  • Born
  • Born
  • No Avatar
  • Joined: Sep 11, 2008
  • Posts: 4
  • Status: Offline

Post September 17th, 2008, 12:10 am

Sure here it is:
Code: [ Select ]
<?xml version="1.0"?>
<root-node>
<Auto merk="Berlingo" sdescription="Dit is geen, nee echt geen test" ldescription="Dit is een langere test" prijs="123"> </Auto>
<Auto merk="Toyota" sdescription="Dit is een test2" ldescription="Dit is een langere test2" prijs="1232"> </Auto>
<Auto merk="Vrachtwagen" sdescription="krte tst" ldescription="Laaaaaaaaaaaaaangge test" prijs="9999"> </Auto>

</root-node>
  1. <?xml version="1.0"?>
  2. <root-node>
  3. <Auto merk="Berlingo" sdescription="Dit is geen, nee echt geen test" ldescription="Dit is een langere test" prijs="123"> </Auto>
  4. <Auto merk="Toyota" sdescription="Dit is een test2" ldescription="Dit is een langere test2" prijs="1232"> </Auto>
  5. <Auto merk="Vrachtwagen" sdescription="krte tst" ldescription="Laaaaaaaaaaaaaangge test" prijs="9999"> </Auto>
  6. </root-node>


Just to be sure, i want to automaticly create textfields for each "<auto>"
  • graphixboy
  • Control + Z
  • Mastermind
  • User avatar
  • Joined: Jul 11, 2005
  • Posts: 1828
  • Loc: In the Great White North
  • Status: Offline

Post September 17th, 2008, 7:59 am

hmm and your only getting the last item? Every thing here looks correct. Could it be that flash is building all the text fields, but stacking them on top of each other so all you ever see is the last one? You could try placing them at different x/y locations per iteration of the loop.
If at first you don't succeed F1... If that doesn't work try Google!
//// Designer, Developer & Teacher - Interactive, Motion and 3D \\\\
Portfolio at WhenImNotSleeping.com
  • graphixboy
  • Control + Z
  • Mastermind
  • User avatar
  • Joined: Jul 11, 2005
  • Posts: 1828
  • Loc: In the Great White North
  • Status: Offline

Post September 17th, 2008, 8:03 am

wait here's your issue. Your hard coding a text field into the loop so it only shows the last loop.

Code: [ Select ]
createTextField("tLabel"+i,this.getNextHighestDepth(),10,i*h,400,old += 40);
tLabel2.html = true;
tLabel2.htmlText = imageName+" "+imagesdescription+" "+imageldescription+" "+imageprijs;
tLabel2.setTextFormat(tfFormatter);
  1. createTextField("tLabel"+i,this.getNextHighestDepth(),10,i*h,400,old += 40);
  2. tLabel2.html = true;
  3. tLabel2.htmlText = imageName+" "+imagesdescription+" "+imageldescription+" "+imageprijs;
  4. tLabel2.setTextFormat(tfFormatter);
should be

Code: [ Select ]
var myTxt = createTextField("tLabel"+i,this.getNextHighestDepth(),10,i*h,400,old += 40);
myTxt.html = true;
myTxt.htmlText = imageName+" "+imagesdescription+" "+imageldescription+" "+imageprijs;
myTxt.setTextFormat(tfFormatter);
  1. var myTxt = createTextField("tLabel"+i,this.getNextHighestDepth(),10,i*h,400,old += 40);
  2. myTxt.html = true;
  3. myTxt.htmlText = imageName+" "+imagesdescription+" "+imageldescription+" "+imageprijs;
  4. myTxt.setTextFormat(tfFormatter);


so I set a variable name for the text field (each loop) called myTxt and then instead of referring to tLabel2 I refer to myTxt to set attributes.
If at first you don't succeed F1... If that doesn't work try Google!
//// Designer, Developer & Teacher - Interactive, Motion and 3D \\\\
Portfolio at WhenImNotSleeping.com
  • Thomper
  • Born
  • Born
  • No Avatar
  • Joined: Sep 11, 2008
  • Posts: 4
  • Status: Offline

Post September 19th, 2008, 12:38 am

Sorry but it doesn't work, now i doesn't show anything at all...
  • graphixboy
  • Control + Z
  • Mastermind
  • User avatar
  • Joined: Jul 11, 2005
  • Posts: 1828
  • Loc: In the Great White North
  • Status: Offline

Post September 19th, 2008, 2:48 pm

can you post your new code?
If at first you don't succeed F1... If that doesn't work try Google!
//// Designer, Developer & Teacher - Interactive, Motion and 3D \\\\
Portfolio at WhenImNotSleeping.com

Post Information

  • Total Posts in this topic: 7 posts
  • Users browsing this forum: No registered users and 64 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.