ok - so I am loading XML and then trying to search and replace some of the text: see below for code (this is after all the xml load stuff....). It is not effecting the xml after loading?!?!?!? please help.
function loadTxt(success:Boolean):Void {
if (success) {
Do you know of a tutorial (or can you help with) that will show me how to cross reference the content.xml with a glossary.xml. Meaning that I will like to load both, then display the content.xml info (like we are doing) then if any glossary term from the glossary.xml is present in the content text it would be hi-lighted and as I roll over the term it will run a function(<a HREF="asfunction:myFunction">call function</a>) that will display the glossary term in a pop-up ( like web sites do!)????
Maybe you can adapt this to what you are trying to do...
Code:
// clear text from text box we put in to fix flash html bug
scroller.txt.t.text = "";
// create new xml object and load text.xml
var txt:XML = new XML();
txt.ignoreWhite = true;
// once the xml is loaded fire the loadTxt function
txt.onLoad = loadTxt;
txt.load("content.xml");
function loadTxt(success:Boolean):Void {
if (success) {
// get our xml start point
var allXML:XMLNode = txt.firstChild;
// create new stylesheet
txtCSS = new TextField.StyleSheet();
// loading our css
cssURL = "css/style.css";
txtCSS.load(cssURL);
// once loaded ..
txtCSS.onLoad = function(success) {
if (success) {
// apply style sheet to description text
scroller.txt.t.styleSheet = txtCSS;
// formmat text field for html
scroller.txt.t.autoSize = "left";
scroller.txt.t.html = true;
// fill our text field with our xml - everything between the <text> tags
scroller.txt.t.htmlText = allXML.childNodes[0].firstChild.nodeValue;
gloss.load("gloss.xml");
}
};
} else {
trace("XML NOT LOADED");
}
}
function searchAndReplace(holder, searchfor, replacement) {
temparray = holder.split(searchfor);
holder = temparray.join(replacement);
return (holder);
}
//
var gloss:XML = new XML();
gloss.ignoreWhite = true;
gloss.onLoad = loadGloss;
function loadGloss(success:Boolean):Void {
if (success) {
var allXML:XMLNode = gloss.firstChild;
var numTerms = allXML.childNodes.length;
for (i = 0; i < numTerms; i++) {
var myTerm = allXML.childNodes[i].attributes.term;
scroller.txt.t.htmlText = searchAndReplace(scroller.txt.t.htmlText, myTerm, "<a HREF='asfunction:myFunction'>" + myTerm + "</a>");
}
}
}
sample used for gloss.xml
PHP Code:
<?xml version="1.0"?>
<content>
<def term = "page">
<![CDATA[<span class='title'>Page</span><br/>about the page.]]>
</def>
<def term = "number">
<![CDATA[<span class='title'>Number</span><br/>about the number.]]>
</def>
Yes... I wrote something similar this morning, but....
Yours is working better....!
Now I need to finish the myFunction() part: Im getting it to pop the terms.swf but its not loading the gloss.xml info....is there a better way to have the term in gloss.xml popup in a bubble????
It depends upon what needs to be displayed for each term. If it's just going to be text, then it's problably easier to do something like a toolltip.
The simplified approach below uses a movieclip, instance name: bubble. With an dynamic html text field, instance name: txt and a movie clip (button), instance name: btnClose.
Code:
var gloss:XML = new XML();
gloss.ignoreWhite = true;
gloss.onLoad = loadGloss;
var myGloss = new Array();
function loadGloss(success:Boolean):Void {
if (success) {
var allXML:XMLNode = gloss.firstChild;
var numTerms = allXML.childNodes.length;
for (i = 0; i < numTerms; i++) {
var myTerm = allXML.childNodes[i].attributes.term;
myGloss[myTerm] = allXML.childNodes[i].firstChild.nodeValue;
scroller.txt.t.htmlText = searchAndReplace(scroller.txt.t.htmlText, myTerm, "<a href=\"asfunction:_root.myFunction," + myTerm + "\">" + myTerm + "</a>");
}
}
}
bubble._visible = false;
function myFunction(term) {
bubble._x = _xmouse + 10;
bubble._y = _ymouse + 10;
bubble.txt.styleSheet = txtCSS
bubble.txt.autoSize = true;
bubble.txt.htmlText = myGloss[term];
bubble._visible = true;
bubble.btnClose.onPress = function(){
this._parent._visible = false;
}
}