Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1034
  • Last Modified:

Array, movieclip, addchild AS3

I have an array that gets populated based on choices a user makes in a form.  Trying to write a function that will then be able to take those array items, convert them to movieclips and then add those mc's to the stage via addChild.  So the array might look like "item1", "item3", "item6" and I just need to know how to get these converted to mc's.
0
moglie
Asked:
moglie
  • 2
  • 2
1 Solution
 
ruidovisualCommented:
I t depends on what kind of movieclips you want. Empty movieclips? Any kind of item?

If it's an specific movieclip you can set a class name for it in the library via the linkage property

So if you already have the array, you can just do that:
//Supposing that you set a MyCustomMC ClassName to your movieclip in the library

var customMc:MyCustomMC;

function convertArrayToMC():void{
  var len = myArray.length;
  for(var i:int = 0; i<len; i++){
    customMc = new MyCustomMC;
    customMc.x = 100; //that's optional
    customMc.y = 100; //that's optional
    this.addChild(customMc); //"this" referrs to mainStage;
  }
}

Open in new window

0
 
moglieAuthor Commented:
There will be specific movieclips in the library with class names such as MyCustomMC1, MyCustomMC2, MyCustomMC3 etc.

So on the first screen I've got a series of checkboxes and if a checkbox is selected, it pushes a string into the array.  If cb1 is selected it'd push, for example, MyCustomMC1, into the array.  If cb3 was selected it'd push MyCustomMC3 into the array and so on.  When completed, the array might look like ("MyCustomMC1", "MyCustomMC3", "MyCustomMC5").

When user goes to the next screen, I need to get these "mc's" from the array and add them to the stage (the mc's are different with different content).
0
 
ruidovisualCommented:
Well just ad some conditionals ; )
var customMc1:MyCustomMC1;
var customMc2:MyCustomMC2;
var customMc3:MyCustomMC3;

function convertArrayToMC():void{
  var len = myArray.length;
  for(var i:int = 0; i<len; i++){
    if(myArray[i]=="MyCustomMC1"){
      customMc1 = new MyCustomMC1;
      customMc1.x = 100; //that's optional
      customMc1.y = 100; //that's optional
      this.addChild(customMc1); //"this" referrs to mainStage;
      continue;
    }else if(myArray[i]=="MyCustomMC2"){
      customMc2 = new MyCustomMC2;
      customMc2.x = 100; //that's optional
      customMc2.y = 100; //that's optional
      this.addChild(customMc2); //"this" referrs to mainStage;
      continue;
    }else if(myArray[i]=="MyCustomMC3"){
      customMc3 = new MyCustomMC3;
      customMc3.x = 100; //that's optional
      customMc3.y = 100; //that's optional
      this.addChild(customMc3); //"this" referrs to mainStage;
      continue;
    }
    
  }
}

Open in new window

0
 
moglieAuthor Commented:
I think that'll work.  Luckily I won't have that many movieclips to work with so the conditionals won't be so bad to write.
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.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now