XML file reading problem - help please

Hi all,
I’m quite new in AS3 programming and I’ve the following 2 problems:

  1. The script will output only the “No text” for the first mouse click into the “txtBox” textbox . Only after second mouse click It will output text (but only the first element content) from the xml file. Why? I need the correct action for the first click…

  2. Only the first element <nadpis> “First heading” is in the texbox txtBox after the second mouse click. The ouptut is well formated by css but the rest of elements contents is missing. I don’t understand why, because the “textOnas” string contains all the content from the o_nas.xml file as evident from the debuger output window (written by the trace command).

I have the following AS3, XML and CSS files:

AS3 file:

 
import flash.display.DisplayObject;
import flash.text.StyleSheet;
import flash.display.MovieClip;
import flash.net.URLLoaderDataFormat;
import flash.text.TextField;
import flash.text.TextFieldType;
import flash.text.StyleSheet;
import flash.xml.*;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.events.Event;
 
var xmlLoader:URLLoader;
var xmlUrl:URLRequest;
var xmlDoc:XMLDocument;
var itemList:XMLList;
var cssLoader:URLLoader;
var cssUrl:URLRequest;
var cssDoc:StyleSheet;
var nactenoXML:Boolean = false;
var nactenoCSS:Boolean = false;
 
bambulkaOnas.addEventListener(MouseEvent.MOUSE_OVER, MC_Onas_MouseOverHandler);
bambulkaOnas.addEventListener(MouseEvent.CLICK, bambulkaOnasClick);
bambulkaOnas.addEventListener(MouseEvent.MOUSE_OUT, MC_Onas_MouseOutHandler);
 
function MC_Onas_MouseOverHandler(event:MouseEvent):void
{
     MC_Onas.alpha = 1;
}
 
function MC_Onas_MouseOutHandler(event:MouseEvent):void
{
     MC_Onas.alpha = 0.3;
}
 
function loadXml():void
{
     xmlUrl = new URLRequest("o_nas.xml");
     xmlLoader = new URLLoader();
     xmlLoader.addEventListener(Event.COMPLETE, onXmlLoaded);
     xmlLoader.load(xmlUrl);
}
function onXmlLoaded(evt:Event):void
{
     xmlDoc = new XMLDocument();
     xmlDoc.ignoreWhite = true;
     xmlDoc.parseXML(xmlLoader.data);
     xmlLoader.removeEventListener(Event.COMPLETE, onXmlLoaded);
     nactenoXML = true;
     loadCss();
}
 
function loadCss():void
{
     cssUrl = new URLRequest("style.css");
     cssLoader = new URLLoader();
     cssLoader.addEventListener(Event.COMPLETE, onCssLoaded);
     cssLoader.load(cssUrl);
}
 
function onCssLoaded(evt:Event):void
{
     cssDoc = new StyleSheet();
     cssDoc.parseCSS(evt.target.data);
     cssLoader.removeEventListener(Event.COMPLETE, onCssLoaded);
     nactenoCSS = true;
}
 
function bambulkaOnasClick(event:MouseEvent):void
{
     var textOnas:String = "";
     loadXml();
 
     if (nactenoXML && nactenoCSS)
     {
          var node1:XMLNode;
          var node1Name:String;
 
          txtBox.selectable = false;
          txtBox.wordWrap = true;
          txtBox.multiline = true;
          txtBox.styleSheet = cssDoc;
          node1 = xmlDoc.firstChild;
          node1Name = node1.nodeName;
 
          if (node1Name == "page")
          {
               for (var ndSubs:XMLNode = node1.firstChild; ndSubs != null; ndSubs=ndSubs.nextSibling)
               {
                    textOnas +=  ndSubs.toString();
               }
               trace(textOnas);
          txtBox.htmlText = textOnas;  //this command will output only the "First heading" text into the 'txtBox' textbox.
                                                     //Where is the rest of the 'textOnas'  string  ???
          }
          else
          {
               txtBox.htmlText = "No text...";
          }
     }
     else
     {
          txtBox.htmlText = "No text...";
     }
}

XML file (o_nas.xml):

 
<?xml version="1.0"?>
<?xml-stylesheet href="style.css" type="text/css" media="screen"?>
 
<page>
 
     <text>
          <nadpis>First heading</nadpis>
          <subnadpis>Subheading 1</subnadpis>
          <text1>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. </text1>
      </text>
 
      <text>
           <nadpis>Second heading</nadpis>
           <subnadpis>Subheading 2</subnadpis>
           <text1>Quisque a urna a tellus placerat mollis.</text1>
      </text>
 
 
 
      <text>     
           <nadpis>Third heading</nadpis>
           <subnadpis>Subheading 2</subnadpis>
           <text1>Donec nibh diam, posuere a, congue feugiat, fringilla eget, ligula. </text1>
      </text>
 
</page>

CSS FILE (style.css):

 
p {
   color: #000000;
   font-family: Times New Roman;
   font-size: 12px;
 
   }
 
nadpis {
   color: #339900;
   font-size: 16px;
   font-weight: bold;
   display: block;
   margin-bottom: 5px;
   margin-top: 20px;
   margin-left: 10px;
   margin-right:10px;
  }
 
subnadpis {
   font-style: italic;
   color: white;
   }
 
text1 {
   text-indent: 20px;
   color: red;
   }  

The debuger output window after the SECOND click:

<text><nadpis>First heading</nadpis><subnadpis>Subheading 1</subnadpis><text1>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. </text1></text><text><nadpis>Second heading</nadpis><subnadpis>Subheading 2</subnadpis><text1>Quisque a urna a tellus placerat mollis. </text1></text><text><nadpis>Third heading</nadpis><subnadpis>Subheading 3</subnadpis><text1>Donec nibh diam, posuere a, congue feugiat, fringilla eget, ligula.</text1></text>

Could someone more experienced help me to solve the above mentioned problems, please?

Thank you in advance…

and SORRY for my English…

Jirka