Question : Animate XML elements separately?

Hey there- I have a simple XML file which loads text into TextFields via a for loop.

 I want to access each of these textfields and animate them one at time onto the stage.  How would I do that with the existing code below. Keep in mind that each textfield should remain evenly spaced to one another and remain as such when new elements are added to the XML doc.

Thanks!
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
AS3:
package {
	import flash.display.Sprite;
	import flash.display.MovieClip;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.net.navigateToURL;
	import flash.text.TextFieldAutoSize;
	//transition import classes
	import fl.transitions.Tween;
	import fl.transitions.easing.*;
 
	public class DocumentClass extends Sprite {
		private var urlLoader:URLLoader;
		private var urlRequest:URLRequest;
		private var xml:XML;
		private var xmlList:XMLList;
		private var newFormat:TextFormat;
 
		public function DocumentClass():void {
			urlLoader = new URLLoader();
			urlRequest = new URLRequest();
			urlRequest.url = 'bc.xml';
			urlLoader.addEventListener(Event.COMPLETE, onXMLLoaded);
			urlLoader.load(urlRequest);
		}
		private function onXMLLoaded(evt:Event):void {
			var widthValue:Number;
			var spacer:Number = 10;
			var startPos:Number = 0;
 
			xml = new XML(evt.target.data);
			xmlList = new XMLList(xml.item);
 
			newFormat = new TextFormat();
			newFormat.color = 0x666666;
			newFormat.font = "Verdana";
			newFormat.size = 14;
			newFormat.underline = false;
 
			for (var i:int = 0; i < xmlList.length(); i++) {
				var s:MovieClip = new MovieClip();
				addChild(container);
				container.mouseChildren = false;
				container.buttonMode = true;
 
				var tf:TextField = new TextField();
				tf.text = xmlList[i].title;
				tf.setTextFormat(newFormat);
				tf.autoSize = TextFieldAutoSize.CENTER;
				tf.border = true;
				tf.borderColor = 0x000000;
				tf.background = true;
 
				tf.x = startPos;
				tf.y = 10;
 
				widthValue = tf.width;
 
				container.path = xmlList[i].path;
				container.addChild(tf);
				container.addEventListener(MouseEvent.MOUSE_DOWN, onSDown);
 
				//keeps the elements evenly spaced on stage
				startPos = startPos + (widthValue + spacer);
			}
		}
		private function onSDown(evt:MouseEvent):void {
			var linkReq:URLRequest = new URLRequest(evt.target.path);
			navigateToURL(linkReq, '_self');
			trace(String(evt.target.path));
		}
	}
}
 
XML:


  
    0000
    /
  
  
    00000000
    /Folder
  
  
    0000
    /Folder/Folder
  
  
    000000
    /Folder/Folder/Folder
  

Open in New Window Select All

Answer : Animate XML elements separately?

Got it. No need to reply, unless you have a better way.  Thanks!
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
package {
	import flash.display.Sprite;
	import flash.display.MovieClip;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.net.navigateToURL;
	import flash.text.TextFieldAutoSize;
	//transition import classes
	import fl.transitions.Tween;
	import fl.transitions.easing.*;
 
	public class DocumentClass extends Sprite {
		private var urlLoader:URLLoader;
		private var urlRequest:URLRequest;
		private var xml:XML;
		private var xmlList:XMLList;
		private var newFormat:TextFormat;
		private var containerArray:Array = new Array();
 
		public function DocumentClass():void {
			urlLoader = new URLLoader();
			urlRequest = new URLRequest();
			urlRequest.url = 'bc.xml';
			urlLoader.addEventListener(Event.COMPLETE, onXMLLoaded);
			urlLoader.load(urlRequest);
		}
		private function onXMLLoaded(evt:Event):void {
			var widthValue:Number;
			var spacer:Number = 10;
			var startPos:Number = 0;
 
			xml = new XML(evt.target.data);
			xmlList = new XMLList(xml.item);
 
			newFormat = new TextFormat();
			newFormat.color = 0x666666;
			newFormat.font = "Verdana";
			newFormat.size = 14;
			newFormat.underline = false;
 
			for (var i:int = 0; i < xmlList.length(); i++) {
				var container:MovieClip = new MovieClip();
				addChild(container);
				container.mouseChildren = false;
				container.buttonMode = true;
 
				var tf:TextField = new TextField();
				tf.text = xmlList[i].title;
				tf.setTextFormat(newFormat);
				tf.autoSize = TextFieldAutoSize.CENTER;
				tf.border = true;
				tf.borderColor = 0x000000;
				tf.background = true;
 
				tf.x = startPos;
				tf.y = 10;
 
				widthValue = tf.width;
 
				container.path = xmlList[i].path;
				//put contents of container(xml.path.title) into separate containerArray
				containerArray.push(container);
				container.addChild(tf);
				container.addEventListener(MouseEvent.MOUSE_DOWN, onSDown);
				//keeps the elements evenly spaced on stage
				startPos = startPos + (widthValue + spacer);
			}
			//tween the MovieClips in the containerArray
			animate();
			//trace out the amount of item in each array
			trace(xmlList.length());
			trace(containerArray.length);
		}
		
		private function animate():void {
			var myTween:Tween;
			var startPos:int = -100;
			var j:int = 0;
			while (j < containerArray.length) {
				myTween = new Tween(containerArray[j],"x",Strong.easeOut,(startPos - (j * 100)),0,.5,true);
				j++
			}
		}
 
		private function onSDown(evt:MouseEvent):void {
			var linkReq:URLRequest = new URLRequest(evt.target.path);
			navigateToURL(linkReq, '_self');
			trace(String(evt.target.path));
			evt.updateAfterEvent();
		}
	}
}
Open in New Window Select All
Random Solutions  
 
programming4us programming4us