Solved

problem with creating a comboBox dynamically in Flash MX 2004

Posted on 2004-09-30
1
214 Views
Last Modified: 2010-04-03
Hi, I am using Flash MX 2004 pro and I have the following code below that:

1.  Generates several ComboBoxes dynamically in a For Loop which works fine.
2.  Generates the Ids for these ComboBoxes dynamically using Arrays, then use these Ids to do 'addItem' to the ComboBoxes.

Step 2 above is not working. Looking at my code below is there an alternative solution to this?

thanks in advance

-------------------------------------------------------------------
import mx.controls.ComboBox;
var YPOS:Number;
YPOS = 10;

var MyComboBox_Array:Array;
MyComboBox_Array = new Array();

for(i=0; i < 3; i++)
{
  MyComboBox_Array[i] = "ComboBox_" + i;
  createClassObject(ComboBox, MyComboBox_Array[i], this.getNextHighestDepth(), {_x:10, _y:YPOS});
  MyComboBox_Array[i].addItem({label:"option1", data:0});
  MyComboBox_Array[i].addItem({label:"option2", data:1});
  MyComboBox_Array[i].addItem({label:"option3", data:2});

  YPOS = YPOS + 100;
}
------------------------------------------------------------------------

0
Comment
Question by:dmehran
1 Comment
 
LVL 10

Accepted Solution

by:
muso120999 earned 250 total points
ID: 12193652
You are just referencing the combobox by name, you need to reference it as an object:

import mx.controls.ComboBox;
var YPOS:Number;
YPOS = 10;

var MyComboBox_Array:Array;
MyComboBox_Array = new Array();

for(i=0; i < 3; i++)
{
  MyComboBox_Array[i] = "ComboBox_" + i;
  createClassObject(ComboBox, MyComboBox_Array[i], this.getNextHighestDepth(), {_x:10, _y:YPOS});
  _root[MyComboBox_Array[i]].addItem({label:"option1", data:0});
  _root[MyComboBox_Array[i]].addItem({label:"option2", data:1});
  _root[MyComboBox_Array[i]].addItem({label:"option3", data:2});

  YPOS = YPOS + 100;
}
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
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.

809 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