Solved

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

Posted on 2011-03-20
2
488 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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…
The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
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.

708 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

20 Experts available now in Live!

Get 1:1 Help Now