Download the files here.
TUTORIAL CONTENTS
  • Introduction
  • Flash/XML Syntax
  • Accessing nodes
  • Digging deeper
  • Power of Attributes
  • HTML and Text in XML
  • Making a Search Engine
  • Preloading XML files
  • XML/FLASH SITES AND TUTORIALS
  • Tupps web site
  • Flash 5 and XML
  • XML Table Constructor Kit
  • Using an XML file to load Chart components
  • Macromedia XML tutorial
  • Integrating XML and Flash in a Web Application
  • AUTHOR´s XML TUTORIALS/FILES
  • XML searchable database I
  • URLs and Asfunctions (II)
  • XML searchable database III
  • XML database Component
  • XML slideshow Component
  • XML scroller menu Component
  • Flash - XML Tutorial

    Digging deeper

    Remember the XML file? If not, click on the link. Within our XML file we have the subnodes of male and female, which are black and blond and which stand for the haircolor of the models. We now want to not only be able to list the male and female models but further subdivide into those with blond haircolor and black haircolor. To do this we have to create another input textfield, which we call inputTextfield2. This will change our initial function startItems as shown below:

                            function startItems(success){
                                 if(success){
                                      if(inputTextfield2.text == ""){
                                          listItems1(this.firstChild);
                                      }
                                      if(inputTextfield2.text != ""){
                                          listItems2(this.firstChild);
                                      }
                                 }else{
                                      mainField.htmlText="No file loaded!";
                                 }
                           }
    

    If nothing is written in that textfield we execute listItems1 function else we execute listItems2 function. The first function is shown below and similar to what we have discussed previously.

                           function listItems1(myItem01) {
                               for (var count01 in myItem01.childNodes) {
                                    modelList = myItem01.childNodes[count01].nodeName;
                                    if (modelList == inputTextfield.text) {
                                         idList = myItem01.childNodes[count01];
                                         mainField.htmlText=idList;
                                         textField1.htmlText=idList.firstChild;
                                    }		 	
                               }	
                           }
    

    The second function now will apprach the children of male and female nodes as shown below:

                          function listItems2(myItem01) {
                              for (var count02 in myItem01.childNodes) {
                                   idList = myItem01.childNodes[count02];
                                   modelList = idList.nodeName;
                                   if ( modelList == inputTextfield.text) {
                                        for( count03 in idList.childNodes){
                                             idList2 = idList.childNodes[count03];
                                             mList = idList2.nodeName;
                                             if ( mList == inputTextfield2.text) {
                                                  mainField.htmlText=idList2;
                                                  textField1.htmlText=idList2.firstChild;
                                             }
                                        }
                                   }		 	
                              }	
                          }
    

    The first part is the same as the upper function but we now add another for ... in .... loop to approach the next childNodes of the nodes male and female and create another if-statement if something is written in the second textfield and that will be only the childNodes for a subcategorie. Compared to many actionscripts this is actually pretty simple. Let´s see how that looks in reality.

    Now we have leant how to approach nodes. In the next lesson we will learn about the power of attributes since we need those for creating a search engine.


    PREVIOUS          NEXT