Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Actionscript 2.0 Loop with XML

Posted on 2008-11-19
Medium Priority
Last Modified: 2013-11-11
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!
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;				
// 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

Open in new window

Question by:webrhp
  • 4
  • 3
LVL 13

Accepted Solution

crooksy88 earned 2000 total points
ID: 22998549
if (ok) {

xmlNodeLength = this.firstChild;
_root.max_entries = xmlNodeLength.childNodes.length;

Author Comment

ID: 22998567

Just curious, do you know how I can add links to my XML data that will work in the flash?
LVL 13

Expert Comment

ID: 22998637
You first have to specify the textfield as a htmlText.

_root.entry_content["mc"+i].entry_txt.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.

            <title><![CDATA[Content Test]]</title>
            <date><![CDATA[November 11th, 2008]]</date>
            <text><![CDATA[This is a <a href="www.domain.com">link</a>]]</text>

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 22998704
You are an unbelievable wealth of knowledge my friend! Thank you again.

Does this CDATA method allow only links. What about images?

Author Comment

ID: 22998794
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?
LVL 13

Expert Comment

ID: 22998887
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>

Author Comment

ID: 22999179
And it works!

Thank you again

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are times in your Flash CS4 application when you want more than a simple pointer or a hand, and it's hard to find an ideal walk-through to tell you what to do.  I spent a few days recently learning my way around making custom cursors in Flash,…
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question