Hi,
I am working on a Flash movie in which I would like to dynamically generate
some "buttons." I am just at the starting point and am having some trouble
figuring out how to properly reference text fields.
The attached code attempts to use variables to create and then reference the
dynamically created movie clip and it's text field. It does not work. When I
test the movie and list variables, I can see the movie clip and the text field,
but the text field is not created within the movie clip and does not show up.
However, if I change all the movie clip and text field references to
non-variables (i.e. entering a string myself), it works fine.
I am working towards an OO approach for this but am trying to understand the
general inner workings of Action Script and if it matters, I am working in MX
2004 Professional and have it set for ActionScript 2.0 (Player 7).
Any thoughts or assistance is most appreciated? Thanks very much!
Craig
// initialization function
function init(){
createButtons("test", 10, 20, 20, 530, 100, "Test Button", " ");
}
// function to create dynamic buttons
function createButtons(instName, dep, x, y, w, h, labl, link) {
// create local variable for button/text field name
var buttName:String;
var text_depth:Number;
var text_content:String;
buttName = instName+"_butt";
text_depth = dep+1;
text_content = labl;
// create Movie Clip as a button
_root.createEmptyMovieClip(instName, dep);
// set MC paramaters
with (instName) {
lineStyle(2, "0xFF0000", 40);
beginFill("0x00FFCC", 20);
lineTo(0, 200);
lineTo(200, 200);
lineTo(200, 0);
lineTo(0, 0);
endFill();
_alpha = 0;
_x = x;
_y = y;
// while referencing the newly created mc, create text field
createTextField(buttName, text_depth, 0, 0, w, h);
}
// set text field properties and content
with(buttName) {
text = text_content;
multiline = true;
wordWrap = true;
border = false;
background = false;
textColor = 0x000000;
}
}
// invoke initialization function
_root.onLoad = init;