Solved

addChild(new thumb[0]); how? adding dynamic var with addChild

Posted on 2011-03-20
2
502 Views
Last Modified: 2012-06-21
I currently have any array representing some linkage names from my library. The images are added to an instanced movieclip on stage.

var thumbs:Array = new Array("thumbSliderImage1","thumbSliderImage2","thumbSliderImage3");

Example where " thumbSliderImage1" is a linkage from library.

thumbSlider1.addChild(new thumbSliderImage1());

How would I go about replacing "thumbSliderImage1" with lets say an index from my array, like thumb[0] - thumbSlider1.addChild(new thumb[0]); ?
0
Comment
Question by:mrsam
2 Comments
 
LVL 29

Accepted Solution

by:
dgofman earned 500 total points
ID: 35176171
In Flex you can use Container APIs

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/core/Container.html

removeChildAt(index:int):DisplayObject
[override] Removes a child DisplayObject from the child list of this Container at the specified index.

addChildAt(child:DisplayObject, index:int):DisplayObject
[override] Adds a child DisplayObject to this Container.

I will also suggest to add name for your new instances before adding into Container

var image:thumbSliderImage1 = new thumbSliderImage1();
image.name = "thumb0";
addChild(image);

In this case you can find this instance and index by name:

getChildByName(name:String):DisplayObject
[override] Returns the child whose name property is the specified String. Container

    getChildIndex(child:DisplayObject):int
[override] Gets the zero-based index of a specific child.


var image:thumbSliderImage1 = getChildByName("thumb0") as thumbSliderImage1;
if(image != null)
          index = getChildIndex(image);
0
 

Author Comment

by:mrsam
ID: 35318606
dgofman - you totally saved me with this - I cant say how much I appreciate you chipping in here!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

First things first - Preparation We need all the part for this install and it's much nicer to have them all on hand when you need them so here's what's required. Download Eclipse 3.5 32 bit (I like the Classic flavour) from here. (http://www.e…
I have found that much of my time doing support ends up being a constant repetition of the same steps to different people.  Early on I stated using web pages with Frequently Asked Questions (FAQs) to alleviate most of the burden.  Sometimes this jus…
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.

895 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now