Variable text field in root cannot reside in a movie clip?
I have a movie clip ("mod_control") that resides within other clips that determines the name of its parent and adds a number to a corresponding text field when they appear on stage (example: "Widget_1_count", "Widget_2_count", etc...)
Using this code in the clip works fine:
// get the parent name, example: "Widget_1"
var this_part = Object(this).parent.name;
// get the current value in the corresponding text field, example: "Widget_1_count"
var c_this_part:Number = Number(Object(root[this_part + "_count"]).text);
// add 1 to the current text field value
var v_this_part:Number = Number(c_this_part+1);
// update the text field with the new value
Object(root[this_part + "_count"]).text = String(v_this_part)
I will eventually have several dozen text fields (for several dozen parts) so I now contain them all in a movieclip with instance name "part_count".
So I added part_count into the target path:
var this_part = Object(this).parent.name;
var c_this_part:Number = Number(Object(root.part_count[this_part + "_count"]).text);
var v_this_part:Number = Number(c_this_part+1);
Object(root.part_count[this_part + "_count"]).text = String(v_this_part)
...but that produced this error:
| Symbol 'mod_control', Layer 'as', Frame 1, Line 20 | 1119: Access of possibly undefined property part_count through a reference with static type flash.display:DisplayObject. |
and then I tried this:
var this_part = Object(this).parent.name;
var c_this_part:Number = Number(Object(root[part_count.this_part + "_count"]).text);
var v_this_part:Number = Number(c_this_part+1);
Object(root[part_count.this_part + "_count"]).text = String(v_this_part)
...but that produced this error:
| Symbol 'mod_control', Layer 'as', Frame 1, Line 20 | 1120: Access of undefined property part_count. |
As is often the case, I may have overlooked an obvious nuance of syntax... could that be the situation here, or is this action simply impossible in flash?
I appreciate the wealth of knowledge and experience here and thank you in advance for giving my issue some thought.
