?
Solved

Actionscript 2.0 Repeat Movieclip XML data

Posted on 2008-11-19
10
Medium Priority
?
971 Views
Last Modified: 2013-11-11
I'm trying to repeat a movie clip on the _y axis, that contains XML data. So far, testing my movie will duplicate the movie clip, only on top of itself. How can I force the repeating movie clips to list vertically?

The flash actionscript is below


MyXML = new XML();
 
MyXML.ignoreWhite = true; 
 
MyXML.onLoad = function(ok) { 
 
if (ok) {
 
   allNodes = this.firstChild.childNodes;
		 
   for (var i = 0; i<3; i++) {
			
      _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; 
			
      duplicateMovieClip (_root.entry_content.entry_info, "mc"+i, i);
 
      _root.entry_height = _root.entry_content["mc"+i]._height;
			
      _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;			
				
      trace(_root.jtitle);
      trace(_root.jdate);
      trace(_root.jtext);
				
}
			
} else {
		  
   trace('error');
			
   }
};
 
MyXML.load('../xml/journal.xml');

Open in new window

0
Comment
Question by:webrhp
  • 5
  • 5
10 Comments
 
LVL 13

Accepted Solution

by:
crooksy88 earned 2000 total points
ID: 22996390
You have to set the Y property for each of the movieclips you add.

e.g.

duplicateMovieClip (_root.entry_content.entry_info, "mc"+i, i);

setProperty(_root.entry_content["mc"+i], _y, i*50);
0
 

Author Comment

by:webrhp
ID: 22996586
This works great! So simple!

But I have one final question before I award...

Would you happen to know how to set the height of my "entry_txt" field to auto?

Basically, repeating the rows works perfectly, but if my XML content is larger than my text field, I get an overlapping. I'd like this repetition to begin, at the bottom of the repeated movie.

Essentially allowing unlimited length to each entry.

Any help is appreciated, and let me know if this requires more points to solve. Thanks so much.
MyXML = new XML();
 
MyXML.ignoreWhite = true;
 
MyXML.onLoad = function(ok) {
      if (ok) {
 
		    allNodes = this.firstChild.childNodes;
		 
            for (var i = 0; i<10; i++) {
			
				_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;
			
				duplicateMovieClip (_root.entry_content.entry_info, "mc"+i, i);
 
				setProperty(_root.entry_content["mc"+i], _y, i*100);			
				
				_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;			
				
				trace(_root.jtitle);
				trace(_root.jdate);
				trace(_root.jtext);
			
            }
			
      } else {
		  
            trace('error');
			
      }
};
 
MyXML.load('../xml/journal.xml');

Open in new window

0
 
LVL 13

Expert Comment

by:crooksy88
ID: 22996685
Unfortunately I don't quite understand what you're saying. Could you post the file somewhere so I could take a look and see what you are meaning?
0
Independent Software Vendors: 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

by:webrhp
ID: 22996797
Below is a link to a zip file containing my .swf and .xml files organized already.

Run the .swf and you'll see my dilemma.

http://sensorywithin.com/files/flash-xml-journal.zip
0
 
LVL 13

Expert Comment

by:crooksy88
ID: 22996984
I see! Although this isn't a complete solution it should get you going on the right path.

in this order...

Duplicate the movie clip

Add the text to the fields

Trace out the _height value of each movieclip so you can see it's height value. trace(_root.entry_content["mc"+i]._height);

If you are seeing the different height values in the output window then you know you can use this info to correctly space the movieclips.

Something like
//get the y value of the previous movieclip
var yval = getProperty(_root.entry_content["mc"+i-1], _y);

//get the height value of the previous movieclip
var hval = getProperty(_root.entry_content["mc"+i-1], _height)

// using the two figures from above, position the new movieclip
// this would add a 20px gap between each movieclip
setProperty(_root.entry_content["mc"+i], _y, yval+(hval+20));




0
 

Author Comment

by:webrhp
ID: 22997018
Oh very cool. I understand where you are going.

Only, tracing the height of my clip, returns only the same value.

I'll accept your previous help, any suggestions?

Thank you
0
 
LVL 13

Expert Comment

by:crooksy88
ID: 22997195
I think you might have to get the height value of the text field within the movieclip rather than the movieclip itself.
0
 

Author Comment

by:webrhp
ID: 22997798
A few syntax issues and now it works!!!!

Thank you so much for your help!

I need to know how to fix my loop, so it doesn't rely on a maximum number. Any ideas?

My final code is below, to anyone who needs help with this type of operation.


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');

Open in new window

0
 
LVL 13

Expert Comment

by:crooksy88
ID: 22998353
if (ok) {

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

Author Comment

by:webrhp
ID: 22998404
Very nice!

Now, I have another question open for the points if you'd like to post this there.

http://www.experts-exchange.com/Software/Photos_Graphics/Web_Graphics/Macromedia_Flash/ActionScript/Q_23919316.html

I'm also looking for a way to add links into the text loaded in from the XML, any ideas?
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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,…
This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
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…
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…
Suggested Courses

839 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