Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

getChildByName() issue with loop

Guest
Oct 28, 2008 Oct 28, 2008

Copy link to clipboard

Copied

I'm trying to use XML to load in 4 images to a movieclip within a movieclip that is already created on the stage. I'm trying to do this in a loop since there are 4 movie clips I'm trying to access. I can get it working without the loop, but it's figuring out the syntax that's causing the problem. Currently I have the following code:

function ParsePics(picsInput:XML):void {
var picsList:XMLList = picsInput.pic.image;
for (var i:int = 0; i < picsList.length(); i++) {
var picsElement:XML = picsList ;
var imageURL = "images/stories/homeflash/" + picsElement;
var loader:Loader = new Loader();

var pic_mc = pics.getChildByName("pic" + (i+1));
pic_mc.addChild(loader);
loader.load(new URLRequest(imageURL));
}
}

The line causing the issues is var pic_mc = pics.getChildByName("pic" + (i+1));
I'm not sure how to access all 4 movieclips - pic1, pic2, pic3 and pic4 without preforming the step 4 separate times. any ideas on what I'm doing wrong?
TOPICS
ActionScript

Views

619
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Oct 28, 2008 Oct 28, 2008

Copy link to clipboard

Copied

You seem to be referring to a container movie clip called pics where I gather your child movieclips are being held. Are you sure that is correct? Are your clips actually directly added to the stage or are they in fact in that container clip?

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 28, 2008 Oct 28, 2008

Copy link to clipboard

Copied

They are in the container clip pics. If I was using AS2 I would refer to them as pics.pic1, pics.pic2 ... and so on.

In AS2 it would be something like;

var pic_mc = this["pic" + (i+1)];
pic_mc.loadMovie(picsElement, 1);

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 29, 2008 Oct 29, 2008

Copy link to clipboard

Copied

The name in getChildByName doesn't refer to the instance name. It refers to the name property of the object, which would have to be assigned when it's added to the display list. I don't think the name property works for an object that was placed on the timeline at authoring time.

You could try using pics.getChildAt(i)

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Nov 10, 2008 Nov 10, 2008

Copy link to clipboard

Copied

LATEST
The name property will work if you gave the clip a name in the authoring environment.

You can still refer to clips that are added to a container clip with the array notation from AS2.

containerClip["name" + index].someProperty does still work.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines