Actionscript 2.0 Loop with XML

Posted on 2008-11-19
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
    LVL 13

    Accepted Solution

    if (ok) {

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

    Author Comment


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

    Expert Comment

    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="">link</a>]]</text>


    Author Comment

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

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

    Author Comment

    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

    This is the correct format for adding the information to the htmlText field.

    blah.htmlText = "<a href=\"\" target=\"_blank\"><img src = \"1_p1.jpg\"><a>";

    So I would imagine this might work within the xml file

    <text><![CDATA[<a href="" target="_blank"><img src = "p1.jpg"><a>"]]</text>

    Author Comment

    And it works!

    Thank you again

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    I know the transition can be hard. We got used to the ease of use ActionScript 2 had, but honestly, it became problematic later on, especially if designers were involved in the project and found it easy to add code as they saw fit. So, this artic…
    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…
    In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
    In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…

    745 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

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now