Flash
  Home arrow Flash arrow Page 3 - A Simple XML-Based Searchable Database
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
FLASH

A Simple XML-Based Searchable Database
By: Joachim Schnier
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 31
    2004-07-21

    Table of Contents:
  • A Simple XML-Based Searchable Database
  • The XML File and Tree
  • The Fla File
  • ActionScript for Search Engine Continuation
  • The Button Scripts

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    A Simple XML-Based Searchable Database - The Fla File


    (Page 3 of 5 )


     
    The Fla file: Stage

    We will first plan and build a stage. Just open the fla file and look at the stage. There are several dynamic textfields, an input field for the search engine and two empty movieclips, which we need for preloading and loading the swf files. You can also load jpg files in Flash MX but I have used swf files because the power of Flash using XML is to have animations played, which makes Flash different from other XML parsers. All textfields have var names except for the big central textfield, which has the textfield name ´InstanceName_0´. This is important, because we are attaching a scrollbar to this field in case the text is larger than the field. I have to thank the Flash MX discussion board where I learned how to do it correctly. The input field also gets a var name (var box in the property inspector). Further we put buttons on the stage but this is of course completely up to you. 

    The Fla file: ActionScript for Buttons, Uploading the XML File

    Now open the actions panel and have a look at the scripts. At the top of the page is the preload script. Check the script attached to modelHolder_1 to learn more about tracing the loading event.

    We first create a general function with two arguments, which will be for the individual name buttons. We call the function ´showModel(modelName,fileName)´. The var modelName is the actual name of the model such as Kim for example. The var fileName is any XML file we want to upload.


    //function to preload pics
    function loadAll(firstPic,lastPic,picName){
      for (j=firstPic;j<=lastPic;j++) {
      duplicateMovieClip (_root.modelHolder_1,"pic_"+j, j);   
      setProperty ("pic_"+j, _alpha, (0));
      loadMovie(picName+j+".swf","pic_"+j);
      loadMovie(picName+j+".swf","modelHolder_1");
      setProperty("modelHolder_1",_alpha, (0));
      }
    }
    loadAll(1,6,"pic_");
    loadMovie("agency.swf","modelHolder");

    //general function to upload and get access to the xml files
    //for the buttons
    function showModel(modelName,fileName) {
      //this is to empty the preloader textfield
      counter="";
      //variables for the name of the model and for the xml file
      var modelName;
      var fileName;
      //uploading the xml, model is just an instance we use here
      model = new XML();
      model.onLoad = newModel;
      //this facilitates accessing the xml tree, since white
      //space is also considered childnode
      //the use of ignoreWhite, however, should be avoided if possible
      model.ignoreWhite = true;
      model.load(fileName);

     
    The Fla file: ActionScript for Buttons, Accessing the XML File

    We now have to get access to the XML file. We do that by creating a function containing a loop. In this function we search for the root node "models".


    //function to get to the root node and the childnodes
    function newModel() {
      //loop going through the xml file whereby childNodes.length is the number of child nodes
      for (var count01=0; count01<=model.childNodes.length; count01++) {
        //the root node name "models"
        if (this.childNodes[count01].nodeName.toLowerCase() == "models") {
          //this var holds the complete xml file
          modelsDescryption = this.childNodes[count01];
          }
        }
        //function to get access to individual childnodes
        //modelsDescryption will carry over the extracted contents from the previous
        //function to the next function
        findModels(modelsDescryption); 
      }

     
    The Fla file: ActionScript for Buttons, Accessing Individual Child Nodes

    In the next function we will get access to child nodes by using another loop. Compare by using trace the contents of the var modelsDyscryption of the previous function with this function and see the difference.


    //here we use a new argument for the function
    function findModels(myModel) {
      var myModel;
      var modelName;
      for (var count02=0; count02<=myModel.childNodes.length; count02++) {
        if (myModel.childNodes[count02].nodeName.toLowerCase() == modelName) {
        //we now have access to one childnode
        //now the var modelsDescryption holds only the contents of the first Child of
        //the childnode "modelName". modelName can be any of
        //the child nodes of our XML document
        modelsDescryption = myModel.childNodes[count02].firstChild;
        //this will show the firstChild content in the scrollbar textfield
        InstanceName_0.text = modelsDescryption;
        //here we are accessing the attribute "name"
        headline = myModel.childNodes[count02].attributes.name;
        //here we are accessing the attribute "photo"
        pic = myModel.childNodes[count02].attributes.photo;
        //we load the swf into an empty MC
        loadMovie(pic,"modelHolder");
        }
       }
      }
     }

     
    The Fla file: ActionScript for search engine

    The first part of the search engine script is similar to the above script except that we don't need any arguments. We do not only search in one XML file but in two. The search is performed by first uploading the XML file and then looking for string matches.


    //this is the function for the search engine
    function searchModel() {
      var modelName;
      model = new XML();
      model.onLoad = newModel;
      model.ignoreWhite = true;
      model.load("fmodels.xml");
      function newModel() {
        for (var count01=0; count01<=model.childNodes.length; count01++) {
          if (this.childNodes[count01].nodeName.toLowerCase() == "models") {
          modelsDescryption = this.childNodes[count01];   
          }
        }
       findMFModels(modelsDescryption); 
     }

     

    More Flash Articles
    More By Joachim Schnier


       · I am interested in looking further into this example but can't seem to figure out...
       · You need to hop along to...
     

    FLASH ARTICLES

    - Critical Flash Vulnerability Heats Up the Web
    - More on Nonpersistent Client-Side Remote Sha...
    - Nonpersistent Client-Side Remote Shared Obje...
    - Using the Decorator Pattern for a Real Web S...
    - Using Concrete Decorator Classes
    - Delving More Deeply into the Decorator Patte...
    - The Decorator Pattern in Action
    - A Simple Decorator Pattern Example
    - Decorator Pattern
    - Organizing Frames and Layers for Flash Anima...
    - Organizing Frames and Layers
    - Using XML and ActionScript with Flex Applica...
    - Interfaces and Events with ActionScript and ...
    - Manipulating Data with ActionScript in Flex ...
    - ActionScript Syntax for Flex Applications







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    Stay green...Green IT