?
Solved

Using a variable in AddChild target in ActionScript 3

Posted on 2010-01-10
2
Medium Priority
?
519 Views
Last Modified: 2013-11-11
I have a collection of instances of a moveClip that already exist in my timeline named emptyThumb_mc0, emptyThumb_mc1, etc.

I'm using XML and a loop to load external images one at a time and I'm trying to cycle through and add them to each of the movieClips using AddChild.

AddChild works just fine if I hardcode the name of the target movieclip like this:
this.thumbGrid_mc.emptyThumb_mc0.addChild(imageLoader);
except of course, then all my images are loaded into that one MovieClip.

I want to use the variable from my loop to cycle through each target movieclip so I changed the code to this:
this.thumbGrid_mc.emptyThumb_mc[i].addChild(imageLoader);

When I change the code to this, I get an 'Error#1010 A term is undefined and has no properties. I've traced the i value and it is has a correct value through each loop. So... is my syntax incorrect, or is just impossible to put a variable into the target path like this?

I've attached the relevant function code

//function that dynamically displays thumbnails
function xmlLoaded(event:Event):void
{
	//take data from XML import and put it into an array variable
	xml = XML(event.target.data);
	xmlList = xml.children();
	//loop that creates a new image loader for each item in the list of images
	for(var i:int = 0; i < xmlList.length(); i++)
	{
		imageLoader = new Loader();
		//get the path to the thumbnail image file for each loader
		imageLoader.load(new URLRequest(xmlList[i].attribute("thumb")));
		//set position for the loader on the stage
		imageLoader.x = 0;
		imageLoader.y = 0;
		//collect path name to large image for each thumbnail and save as the name attribute
		imageLoader.name = xmlList[i].attribute("source");
		//add thumbnail to the stage
		trace(i);
		this.thumbGrid_mc.emptyThumb_mc[i].addChild(imageLoader);
		//add listener to thumbnail to react to a mouse click to show full-size image
		imageLoader.addEventListener(MouseEvent.CLICK, showPicture);
	}
}

Open in new window

0
Comment
Question by:beemerrider130hp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 19

Accepted Solution

by:
moagrius earned 500 total points
ID: 26279321
try this:
this.thumbGrid_mc["emptyThumb_mc" + i].addChild(imageLoader);

Open in new window

0
 

Author Closing Comment

by:beemerrider130hp
ID: 31675255
That did the trick, thank you so much!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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 come across a lot of question about how to access things in the document class from a movieclip, or accessing something from a movieclip in the document class. It took me a while to figure this out but once I did it makes life so much easier. …
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.
Suggested Courses
Course of the Month11 days, 13 hours left to enroll

752 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