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.
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.
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?
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
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.
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
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..