A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: xml list with mouseover

  1. #1
    Member
    Join Date
    May 2002
    Posts
    42

    xml list with mouseover

    Hi,

    Please help; I've spent almost a week searching this site with little luck. I need to:
    1)start with an xml file
    2)generate a list of terms (as in a glossary or dictionary)
    3)mouseover each term to display a definition next to the list of terms

    I've got 1 and 2 working perfectly with some help from postings by Ed Reyes on this site.

    Here's a little sample of my xml file:
    <GLOSSARY>
    <links id="001">
    <term>Caliper tool</term>
    <def>A caliper tool is an adjustable measuring tool.</def>
    </links>
    </GLOSSARY>

    The xml is then converted to a variable called links, and the code below generates the list of terms and displays them in a dynamic textbox called list.

    list = "";
    for (i=0; i<links.length; i++) {
    list += links[i].term + "<br>";
    }
    stop();

    From here, I just don't know what to do. I've read about using functions and movieclips, but nothing that I can get to work. Any help at all would be so appreciated...even if it's only a hint at what I should try to do next.

    Thanks a bunch,
    Debbie

  2. #2
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    hi debbie heres the actionscript for what you wanna do but first remember to

    (1) create a dynamic textfield on your stage with instance name definition_txt

    (2) Define your xml file like this and name it dictionary.xml

    Code:
    <dictionary>
    
      <word>
      <term>caliper</term>
      <definition>this is defin of caliper</definition>
      </word>
    
     <word>
      <term>mountain</term>
      <definition>this is defin of mountain</definition>
      </word>
    
    
      <word>
      <term>car</term>
      <definition>car defintion </definition>
      </word>
    
    
     <word>
      <term>animal </term>
      <definition>definition of animal</definition>
     </word>
    
    
    </dictionary>

    Heres the actionscript for you to add on your actions layer. (p.s its not the easiest code to understand, and im sure there are easier ways of doing the same thing, i just whizzed it out as it came to my head)..the movieclips are created dynamically on the stage, so u yourself dont have to create any.

    Code:
    mcMain = this;
    definition_txt.autoSize="left";
    
    var dictionary_xml:XML = new XML();
    dictionary_xml.ignoreWhite = true;
    dictionary_xml.load("dictionary.xml");
    
    dictionary_xml.onLoad = function(bSuccess:Boolean){
    	if(bSuccess){
    		initializeXML();
    		}else{
    		trace("error loading xml file");
    		}
    	
    }
    
    function initializeXML():Void{
    	var word:String;
    	var definition:String;
    	var nDepth:Number;
    	var wordHolder_mc:MovieClip;
    	var nX:Number = 20;
    	
    	var parent:XMLNode = dictionary_xml.firstChild;
    	for(var i:Number = 0; i<parent.childNodes.length;i++){
    		for( var j:Number = 0; j<parent.childNodes[i].childNodes.length;j++){
    		word = parent.childNodes[i].childNodes[j].firstChild.nodeValue;
    		//trace(word);
    		
    		if(j==0){
    		definition = parent.childNodes[i].childNodes[j+1].firstChild.nodeValue;
    		nDepth = mcMain.getNextHighestDepth();
    		wordHolder_mc = mcMain.createEmptyMovieClip(definition,nDepth);
    		wordHolder_mc.createTextField("textfield",wordHolder_mc.getNextHighestDepth(),0,0,0,0);
    		
    wordHolder_mc.onRelease = function(){
    	definition_txt.text = this._name;
    	}
    
    wordHolder_mc.textfield.autoSize = "center";
    wordHolder_mc.textfield.text = word;
    wordHolder_mc._x = nX;
    nX+=60;
    
    
    	  }
    	}
      }
    }
    Last edited by silentweed; 05-20-2005 at 09:24 AM.
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  3. #3
    Member
    Join Date
    May 2002
    Posts
    42
    Hi silentweed,

    I can't believe how quickly you answered and how much work you did for me. Unfortunately, I can't get it to work. I've double checked everything several times to make sure that I did just what you said to do, but no luck.

    I'm sure this is my fault because I didn't specify that I was using MX. Because of this, I had to remove the ":Void" from the "function initializeXML():Void{" line in your code before I was able to publish.

    Is there an easy fix to your code to make it work with MX, or should I finally get around to updating my software?

    Thanks a bunch,
    Debbie

  4. #4
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    Hi no problem.. had some time to spare ..well im not too familiar with MX but try the following:

    Code:
    cMain = this;
    definition_txt.autoSize="left";
    
    var dictionary_xml = new XML();
    dictionary_xml.ignoreWhite = true;
    dictionary_xml.load("dictionary.xml");
    
    dictionary_xml.onLoad = function(bSuccess){
    	if(bSuccess){
    		initializeXML();
    		}else{
    		trace("error loading xml file");
    		}
    	
    }
    
    function initializeXML(){
    	var word;
    	var definition;
    	var nDepth;
    	var wordHolder_mc;
    	var nX = 20;
    	
    	var parent = dictionary_xml.firstChild;
    	for(var i:Number = 0; i<parent.childNodes.length;i++){
    		for( var j:Number = 0; j<parent.childNodes[i].childNodes.length;j++){
    		word = parent.childNodes[i].childNodes[j].firstChild.nodeValue;
    		//trace(word);
    		
    		if(j==0){
    		definition = parent.childNodes[i].childNodes[j+1].firstChild.nodeValue;
    		nDepth = mcMain.getNextHighestDepth();
    		wordHolder_mc = mcMain.createEmptyMovieClip(definition,nDepth);
    		wordHolder_mc.createTextField("textfield",wordHolder_mc.getNextHighestDepth(),0,0,0,0);
    		
    wordHolder_mc.onRelease = function(){
            trace(this._name);
    	definition_txt.text = this._name;
    	}
    
    wordHolder_mc.textfield.autoSize = "center";
    wordHolder_mc.textfield.text = word;
    wordHolder_mc._x = nX;
    nX+=60;
    
    
    	  }
    	}
      }
    }
    ive put a trace statment in

    wordHolder_mc.onRelease = function(){
    trace(this._name);
    definition_txt.text = this._name;
    }

    so u can tell if its a problem with your dynamic text field as well.
    Remember to CLICK on each word so the defintion appears..if u wanna change that just change the above function to onRollover

    Remember a good technique to find out what is going wrong is to put various trace statments in the code so you can see where the code is going wrong
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  5. #5
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    oops the first line should say

    mcMain not cMain
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  6. #6
    Member
    Join Date
    May 2002
    Posts
    42
    I just don't know what I'm doing wrong.

    I started with a brand new .fla with one frame.
    I pasted your code into the actions panel.
    I pasted your xml into notepad and saved it as dictionary.xml.
    I created a dynamic text box and made the instance name dictionary_txt.
    I changed cMain to mcMain.
    I even double checked to make sure everything was in the same directory.

    I get nothing but white screen. I can tell from the cursor that there is a one line text box on the screen, but that's it.

    Is 9am too early to drink?
    Debbie

  7. #7
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    dont any of the words from the dictionary appear on the stage either? post ur fla on here ill see wots going on
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  8. #8
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    the instance name of the text field should be definition_txt not dictionary_txt
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  9. #9
    Member
    Join Date
    May 2002
    Posts
    42
    Thanks again. I did have the instance name of the text field as definition_txt. I just accidently told you that I had named it dictionary_txt. That got my hopes up for a minute, until I double checked it.
    The file is attached.
    Debbie
    Attached Files Attached Files

  10. #10
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    yeh ur right sorry its not apparent to me right now why it isnt working...its a version problem because it works for mx 2004 but when i change the version setting to MX in publish settings it doesnt work... maybe someone who uses MX will be able to tell u whats incompatible..if i figure it out ill let u know...best of luck..
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center