Solved

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

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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

This is a very simple example to help those of you who are still migrating from AS2 to AS3 understand the redesigned event model in AS3. In AS2.0, event functions (that is, the function to be performed when an event is fired) were stored as a pro…
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. …
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

803 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