Question

how to create AS3 duplicate movie clip and track x,y positions

Asked by: bschave2

I would like to dupluicate movie clips that read in xml data into each duplicated movie clip. these movie clips will serve as buttons for an accordian menu. How can I duplicate movie clips and keep track of there _x and _y position?

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-08-21 at 08:54:43ID24671787
Topics

ActionScript

,

Adobe Flash

Participating Experts
1
Points
500
Comments
6

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. load Movie(clip)
    I know Load Movie can load a .swf onto a level or into a target. I want to load an existing movie clip into a target at run time This doesn't work as it is looking for a url. Load Movie ("/store", "/st1") Anyone know how I can load my existing mov...
  2. changing the depth of a duplicated movie clip
    is it possible to change the depth (level) of a duplicated movie clip via ActionScript?
  3. Duplicate movie clip problem
    Hi there, I have a small problem with the duplicateMovieClip command in flash. The problem is that when I use this command the new movie clips appear over the top of everything else on the stage, even if the movie clip being duplicated is on the bottom most layer. Is there...
  4. Duplicate movie clip
    Hi all, I got these movie clips with same instance names _root.animals.dog _root.mvHolder I want to duplicate dog movieclip into mvHolder movieclip the code on dog movie on (press) { duplicateMovieClip(this, "myanimal", _root.getNextHighestDepth()); } but I...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: blue-geniePosted on 2009-08-22 at 02:19:08ID: 25157997

you should create a class for each of the items then create instances of them in the base class and add them to the stage

var obj:ClassName;

obj:ClassName = new ClassName;
addChild(obj);

 

by: bschave2Posted on 2009-08-24 at 12:59:12ID: 25171892

okay, I have an accordian menu that basically loads in the butons with text,...NO content yet.  I am now telling the duplicated movie clip to play a frame within that movieclip. I now want to load another xml file, to produce the content of this because I am setting up animations within the duplicated movie clip. I can get the xml file items to get into their variables, but the movie clip within the movie clip  that is supposed to load all of this content is not showing up. Hope you can help.

code on in root of file
 
//import tweenlite classes
import gs.TweenLite;
import gs.globals;
import gs.easing.*;
 
var masker;
 
var MENU_ARRAY:Array; //used to save the items data
var OPENED_MENU:int; //to inform the menu that should be open at startup
var MOVE_ON_MOUSE_OVER:Boolean=false; //tha name says everything
var xmlLoader:URLLoader; //the xml loader
 
loadXML("menu2.xml"); //load the xml
 
function loadXML(Uri:String):void {
	xmlLoader = new URLLoader();
	xmlLoader.addEventListener(Event.COMPLETE, onComplete);
	xmlLoader.addEventListener(IOErrorEvent.IO_ERROR, onError);
	xmlLoader.load(new URLRequest(Uri));
}
function onError(evt:ErrorEvent):void {
trace("cannot load xml file");
}
 
function onComplete(evt:Event):void {
//read and load xml into array, by parsing it using prepareMenu
MENU_ARRAY=prepareMenu(xmlLoader.data.toString());
placeItemsOnStage(); //place all required items on stage.
}
 
function placeItemsOnStage():void {
var pos:Number=0;
var labelStyle:TextFormat;
var mytext:String = '';
 
//define the container properties
menuContainer.x=0;
menuContainer.y=0;
 
for(var c:int=0; c<MENU_ARRAY.length; c++) {
		var it:menuItem = new menuItem; //load out menuItem, because its exported to AS, we can use it here
		it.x=c*30; //its the gray border width
		it.y=0; //place on top
		it.id="Item-"+c; //id the menuItem
		it.name="Item-"+c; //name de menuItem
		it.posX=pos; //actual pos, useful to open and know is position
		it.itemLabel.text=String(MENU_ARRAY[c].Ititle).toUpperCase(); //load the label in uppercase
		
		
		mytext = it.itemLabel.text;
		var a:String = mytext;
		var aa:int = mytext.length;
		
		var b:String = '';
		var e:int = 0;
		var d:int = 1;
		var f:String = '';
		
		for (var i:int=0; i<aa; i++)
		{
			if (i == 0)
			{
				b = a.substr(e,1) + "\n";
			}
			else
			{
				b = b + a.substr(e,1) + "\n";
			}
			e = e + 1;
			d = d + 1;
		}
		it.itemLabel.text = b;
		
		labelStyle= new TextFormat();
		labelStyle.color = MENU_ARRAY[c].Icolor; //this must be an hexadecimal color: 0xffcc00
		labelStyle.bold = true; //this must be an hexadecimal color: 0xffcc00
		it.itemLabel.setTextFormat(labelStyle); //apply the textFormat.
		it.tweenmc.stop();
		
		it.addEventListener(MouseEvent.CLICK, onMouseClick); //add mouse click listener
		if(MOVE_ON_MOUSE_OVER==true) it.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver); //if configured, load the mouse over event
		it.useHandCursor=true;  //use hand cursor
		it.buttonMode=true; //buttonMode
		it.itemText.visible=false; //hide the textField
		menuContainer.addChild(it); //add the menu item as child
 
		//if(String(MENU_ARRAY[c].IcontentType)=="image/swf")	{ //check the content and load things accordint to it
//			var ldr:Loader = new Loader();
//			ldr.x=30;
//			ldr.y=0;
//			it.addChild(ldr);
//			ldr.load(new URLRequest(MENU_ARRAY[c].IcontentData.toString()));		
		//}
//		else if(String(MENU_ARRAY[c].IcontentType)=="text") {
//			it.itemText.visible=true;
//			it.itemText.text=MENU_ARRAY[c].IcontentData.toString();
//		}
		
		pos+=28; //the next menuItem x position
	}
 
	//put mask in place
	masker.width=(MENU_ARRAY.length*29+800)
	masker.height=menuContainer.height;
	masker.x=0;
	masker.y=0;
 
	moveItem(OPENED_MENU-0); //open menu confirured in XML
	
}
 
function onMouseOver(evt:MouseEvent):void {
if(evt.target.name.toString()=="buttonBack") prepareMove(evt)
if(evt.target.name.toString()=="tweenmc") prepareMove(evt)
}
 
function prepareMove(evt:MouseEvent):void {
	var targetName:String = evt.currentTarget.name.toString(); //get the menuItem 
	var temp:Array = targetName.split("-"); //split his name: Item-x
	trace(temp)
	var itemNumber:int=(temp[1]); //got item number
	moveItem(itemNumber); //move it
}
 
function onMouseClick(evt:MouseEvent):void {
	if(evt.target.name.toString()=="buttonBack")  prepareMove(evt); //mouse action was done in buttonBack
	//else trace("Item "+evt.currentTarget.name+" clicked!"); //mouse action was made on accordion area
	//this.tweenmc.gotoAndPlay(2)
	//evt.target.name.tweenmc.gotoAndPlay(2); //trace(evt.target.name.toString()); 
	//mouse action was done in buttonBack
	//(evt.target as menuItem).tweenmc.gotoAndPlay(2);
	//(evt.target as menuItem).tweenmc.gotoAndStop(2);
 
	else 
	{
		globals.num.foo = 2;
		trace(globals.num.foo);
		//(evt.currentTarget as menuItem).tweenmc.gotoAndPlay(2);
		trace("Item "+evt.currentTarget.name+" clicked!");
	} //trace("Item "+evt.currentTarget.name+" clicked!"); //mouse action was made on accordion area
}
 
 
function moveItem(num:int):void {
	var itemToMove:menuItem=menuContainer.getChildByName("Item-"+String(num)) as menuItem;
	itemToMove.tweenmc.gotoAndPlay(2);
	itemToMove.gotoAndPlay(2);
	//get the menuItem child
		for(var m=0;m<MENU_ARRAY.length;m++) //move one-by-one to the new position
		{
			var tempMc = menuContainer.getChildByName("Item-"+m);
			if(tempMc.x > itemToMove.x) TweenLite.to(tempMc, 1, {x:((tempMc.posX) + itemToMove.width-30), ease:Quart.easeOut}); //see tweenLite for info about this.
			else if(tempMc.x <= itemToMove.x) TweenLite.to(tempMc, 1, {x:(tempMc.posX), ease:Quart.easeOut});	
		}
		
}
 
function prepareMenu (XMLData:String):Array
		{
			//make sure it cames in XML
			var menuXML:XML = new XML(XMLData);
			//just in case
			menuXML.ignoreWhitespace = true;
		
			//get XML item's entrys
			var XMLItems = menuXML.descendants("item");
 
			//load all items into an array
			var itemsArray:Array = new Array();
			var itemObj:Object;
			for(var i in XMLItems)
			{
				itemObj=new Object();
				itemObj.Ititle=XMLItems[i].@Ititle;
				itemObj.IcontentType=XMLItems[i].@IcontentType;
				itemObj.IcontentData=XMLItems[i].@IcontentData;
				itemObj.Icolor=XMLItems[i].@Icolor;
				itemObj.itemID="menu"+i;
				itemsArray.push(itemObj);
			}
		OPENED_MENU=menuXML.@menuOpen; //get menu for open.
 	 	MOVE_ON_MOUSE_OVER=(menuXML.@moveOnMouseOver.toString()=="true" ? true : false); //get the option for load or not mouseOver open
		return itemsArray;
}
//finish.
stop();
 
 
 
 
code on root of duplicated movie clip that was created above.
 
stop();
var xmlLoader2:URLLoader; //the xml loader
 
var MENU_ARRAY2:Array; //used to save the items data
var OPENED_MENU2:int; //to inform the menu that should be open at startup
var MOVE_ON_MOUSE_OVER2:Boolean=false; //tha name says everything
loadXML("in_menu.xml"); //load the xml
 
function loadXML(Uri:String):void {
	xmlLoader2 = new URLLoader();
	xmlLoader2.addEventListener(Event.COMPLETE, onComplete2);
	xmlLoader2.addEventListener(IOErrorEvent.IO_ERROR, onError2);
	xmlLoader2.load(new URLRequest(Uri));
}
 
function onError2(evt:ErrorEvent):void {
trace("cannot load xml file");
}
 
function onComplete2(evt2:Event):void {
//read and load xml into array, by parsing it using prepareMenu
MENU_ARRAY2=prepareMenu2(xmlLoader2.data.toString());
placeItemsOnStage2(); //place all required items on stage.
}
 
function placeItemsOnStage2():void 
{
	var pos2:Number=0;
	var labelStyle2:TextFormat;
	
	for(var c2:int=0; c2<MENU_ARRAY2.length; c2++) 
	{
		var it:menuItem = new menuItem;
		var it2:inMenu = new inMenu; //load out menuItem, because its exported to AS, we can use it here
		it.it2.x=c2;//*30; //its the gray border width
		it.it2.y=0; //place on top
		it.it2.id="Item-"+c2; //id the menuItem
		it.it2.name="Item-"+c2; //name de menuItem
		it.it2.posX2=pos2; //actual pos, useful to open and know is position
		it.it2.xmltxt.text=String(MENU_ARRAY2[c2].Ititle).toUpperCase(); //load the label in uppercase
		trace(it2.xmltxt.text);
		labelStyle2= new TextFormat();
		labelStyle2.bold = true; //this must be an hexadecimal color: 0xffcc00
		it.it2.xmltxt.setTextFormat(labelStyle2); //apply the textFormat.
		trace(it2.xmltxt.text);
		it.it2.useHandCursor=true;  //use hand cursor
		it.it2.buttonMode=true; //buttonMode
			var ldr2:Loader = new Loader();
			ldr2.x=33;
			ldr2.y=0;
			it2.addChild(ldr2);
			ldr2.load(new URLRequest(MENU_ARRAY2[c2].IcontentData.toString()));	
			
			
			
	}
	
	pos2+=28;
}
 
function prepareMenu2 (XMLData2:String):Array
		{
			//make sure it cames in XML
			var menuXML2:XML = new XML(XMLData2);
			//just in case
			menuXML2.ignoreWhitespace = true;
		
			//get XML item's entrys
			var XMLItems2 = menuXML2.descendants("image1");
 
			//load all items into an array
			var itemsArray2:Array = new Array();
			var itemObj2:Object;
			for(var i in XMLItems2)
			{
				itemObj2=new Object();
				itemObj2.Ititle=XMLItems2[i].@Ititle;
				trace(itemObj2.Ititle);
				//itemObj2.IcontentType=XMLItems2[i].@IcontentType;
				itemObj2.IcontentData=XMLItems2[i].@IcontentData;
				trace(itemObj2.IcontentData);
				//itemObj2.Iimage=XMLItems2[i].@Iimage;
				itemObj2.Iurl=XMLItems2[i].@Iurl;
				trace(itemObj2.Iurl);
				
				//trace(itemObj2.Iurl);
				
				itemObj2.itemID="menu"+i;
				itemsArray2.push(itemObj2);
			}
		OPENED_MENU2=menuXML2.@menuOpen; //get menu for open.
 	 	MOVE_ON_MOUSE_OVER2=(menuXML2.@moveOnMouseOver.toString()=="true" ? true : false); //get the option for load or not mouseOver open
		return itemsArray2;
}
                                              
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:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:

Select allOpen in new window

 

by: blue-geniePosted on 2009-08-24 at 22:12:31ID: 25174666

this would make more sense if you could upload your files.

 

by: bschave2Posted on 2009-09-08 at 11:48:08ID: 25284853

i went another way and just coded from the stage. thanks anyway.

 

by: bschave2Posted on 2009-09-08 at 12:27:02ID: 31618927

figured out the issue before I was helped.

 

by: blue-geniePosted on 2009-09-08 at 21:57:56ID: 25288323

in that case just have your question closed and your points refunded.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...