user1005253
user1005253

Reputation: 404

Editing text of labels inside of Button - AS3

I have created a button name:

menuButton

and inside the button I have two textboxes with following names;

name_mb

level_mb

I have created around 6 instances of this object/button. I'm trying to change the text of these textboxes for each these instances of button(each instance has different names).

This is how I'm trying to do it;

menu_One.level_mb.text = "hello";

menu_One; The name of instance

However, I get following error:

Symbol 'menuButton', Layer 'Layer 1', Frame 1 Warning: The instance name 'level_mb' is declared on an object of type fl.text.TLFTextField but there is a conflicting use of the instance name 'level_mb' on an object of type flash.display.InteractiveObject.

Symbol 'menuButton', Layer 'Layer 1', Frame 1 Warning: The instance name 'name_mb' is declared on an object of type fl.text.TLFTextField but there is a conflicting use of the instance name 'name_mb' on an object of type flash.display.InteractiveObject

. Is this due to multiple instances of same object/button?

Alternatively I can create a new button for each of the buttons I need, and give it text manually. I would prefer to do it via code however, as I will have around 10 buttons, and in future if I need to add more, it will be much easier.

I can provide more code if needed.

Upvotes: 0

Views: 1506

Answers (1)

Kodiak
Kodiak

Reputation: 5978

You may try using the strict AS3 syntax:

menu_One.getChildByName("level_mb")

And casting this as a TextField to access the text property:

(menu_One.getChildByName("level_mb") as TextField).text = "hello";

Upvotes: 2

Related Questions