-
Dynamically naming fields
Hi all,
How do i dynamically name the myData.comboData field?
It should be called something along the lines of myData.comboData1, myData.comboData2, myData.comboData3 etc.
Code:
for (var i=0; i<myData.numrows ; i++) {
myComboBox.addItemAt(i,myData.comboData[i]);
}
Cheers,
macca
-
Senior Member
There are two ways of coming up with a numbered variable name:
1.
eval("myData.comboData" + i);
2.
myData["comboData" + i];
In both cases, if i == 2, then you get
the equivalent of
myData.comboData2
* * *
However,
I don't see anything wrong with using an array, which is what your example code appears to be doing. Seems like a lot of folks use numbered variable names as a means of avoiding learning to use arrays effectively.
- Jim
-
Thanks jpen, that did the trick.
Can i ask another question?
If i have the following:
Code:
myData = new LoadVars();
myData.onLoad = function(){
placeTheDataIntoTheRightPlace();//call the function that handles the data.
};
myData.load("http://localhost/pm/include/myData.php");
placeTheDataIntoTheRightPlace = function(){
for (var i=0; i<myData.numrows ; i++) {
myComboBox.addItemAt(i,eval("myData.comboData" + (i+1)),6);
}
};myData = new LoadVars();
myData.onLoad = function(){
placeTheDataIntoTheRightPlace();//call the function that handles the data.
};
myData.load("http://localhost/pm/include/myData.php");
placeTheDataIntoTheRightPlace = function(){
for (var i=0; i<myData.numrows ; i++) {
myComboBox.addItemAt(i,eval("myData.comboData" + (i+1)),6);
}
};
My question is how can i goto frame 6 of the main movie when a list item is selected?
Cheers,
macca
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|