Solved

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

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Media streaming on premise 13 52
Imac (Gaphic Card 4GB, 32 RAM) and After effects? 4 90
C# Login snippet/framework recommended? 4 103
how to blot out certain parts of a video 2 88
This is intended to introduce all collision detection principles in flash, their strengths, weaknesses and workarounds. The main method for Collision Detection in flash is using hitTestObject. But unless you'll be pushing rectangular shapes without …
Here are some practices and techniques that can be adopted into your Flash/Flex application development process. Note: Not all "performance tips" provide an immediately-recognizable benefit.   This article does not include timing validation data,…
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.

840 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