webrhp
asked on
Actionscript 2.0 Loop with XML
This piece of code I have below, has a limited number in its loop.
I need help creating a loop that will not rely on a maximum number.
Maybe a "while" loop? Im not sure how to implement this though... Please help!
I need help creating a loop that will not rely on a maximum number.
Maybe a "while" loop? Im not sure how to implement this though... Please help!
MyXML = new XML();
MyXML.ignoreWhite = true;
MyXML.onLoad = function(ok) {
if (ok) {
// Loop Limit
_root.max_entries = 10;
for (var i = 0; i < _root.max_entries; i++) {
// Put XML Contents into Variables
_root.jtitle = this.firstChild.childNodes[i].childNodes[0].firstChild.nodeValue;
_root.jdate = this.firstChild.childNodes[i].childNodes[1].firstChild.nodeValue;
_root.jtext = this.firstChild.childNodes[i].childNodes[2].firstChild.nodeValue;
//trace(_root.jtitle);
//trace(_root.jdate);
//trace(_root.jtext);
// Duplicate Entry clip, and Assign New Dynamic Name
duplicateMovieClip (_root.entry_content.entry_info, "mc"+i, i);
// Wrap Size of Major Text Field to Size of Content
_root.entry_content["mc"+i].entry_txt.autoSize = "center";
// Enter Text from XML Into Movie Clip
_root.entry_content["mc"+i].title_txt.text = _root.jtitle;
_root.entry_content["mc"+i].date_txt.text = _root.jdate;
_root.entry_content["mc"+i].entry_txt.text = _root.jtext;
// Get the y value of the previous movieclip
var yval = getProperty(_root.entry_content["mc" + (i - 1)], _y);
// trace("previous clip y position " + yval);
// Get the height value of the previous movieclip
var hval = getProperty(_root.entry_content["mc" + (i - 1)], _height)
// trace("height of previous clip " + hval);
// Space in pixels between each clip
_root.mc_spacing = 10;
// Using the two figures from above, position the new movieclip
setProperty(_root.entry_content["mc"+i], _y, yval + (hval + _root.mc_spacing));
}
} else {
// If XML isn't loaded, trace error
trace('Error XML Not Loaded!');
}
};
// Load XML File
MyXML.load('../xml/journal.xml');
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You first have to specify the textfield as a htmlText.
e.g.
_root.entry_content["mc"+i ].entry_tx t.htmlText = _root.jtext;
Then in your xml file you can add html tags to create links. In order to do this though you have to enclose your content within CDATA tags. e.g.
<entry>
<title><![CDATA[Content Test]]</title>
<date><![CDATA[November 11th, 2008]]</date>
<text><![CDATA[This is a <a href="www.domain.com">link</a>]]</text>
</entry>
e.g.
_root.entry_content["mc"+i
Then in your xml file you can add html tags to create links. In order to do this though you have to enclose your content within CDATA tags. e.g.
<entry>
<title><![CDATA[Content Test]]</title>
<date><![CDATA[November 11th, 2008]]</date>
<text><![CDATA[This is a <a href="www.domain.com">link</a>]]</text>
</entry>
ASKER
You are an unbelievable wealth of knowledge my friend! Thank you again.
Does this CDATA method allow only links. What about images?
Does this CDATA method allow only links. What about images?
ASKER
Ah ha! Nevermind!
It turns out, I have to embed my font's characters, and it seems to work perfectly!
Though Im still having some small issues with linking the image, everything is coming along very well.
Any ideas for image links?
It turns out, I have to embed my font's characters, and it seems to work perfectly!
Though Im still having some small issues with linking the image, everything is coming along very well.
Any ideas for image links?
This is the correct format for adding the information to the htmlText field.
blah.htmlText = "<a href=\"http://maps.google.com\" target=\"_blank\"><img src = \"1_p1.jpg\"><a>";
So I would imagine this might work within the xml file
<text><![CDATA[<a href="http://maps.google.com" target="_blank"><img src = "p1.jpg"><a>"]]</text>
blah.htmlText = "<a href=\"http://maps.google.com\" target=\"_blank\"><img src = \"1_p1.jpg\"><a>";
So I would imagine this might work within the xml file
<text><![CDATA[<a href="http://maps.google.com" target="_blank"><img src = "p1.jpg"><a>"]]</text>
ASKER
And it works!
Thank you again
Thank you again
ASKER
Just curious, do you know how I can add links to my XML data that will work in the flash?