actionscript 3 - flash simple button with text -
i have simple button in flash cs5 - as3 called btn1 dynamic text called text_txt inside inside it.
the goal change text however...
btn1.visible=true; // works fine this.btn1.text_txt.text="hello"; // give null error
my question is: how programatically change text inside button ?
because have flashdevelop can show how programmatically.
if dealing sprite
object(which recommend) following how access textfield
in sprite
object:
var textfield:textfield = new textfield(); textfield.name = "textfield"; textfield.mouseenabled = false; var rectangleshape:shape = new shape(); rectangleshape.graphics.beginfill(0xff0000); rectangleshape.graphics.drawrect(0, 0, 100, 25); rectangleshape.graphics.endfill(); var buttonsprite:sprite = new sprite(); buttonsprite.addchild(rectangleshape); buttonsprite.addchild(textfield); addchild(buttonsprite); var tf:textfield = textfield(buttonsprite.getchildbyname("textfield")); tf.text = "button sprite text";
first textfield
object called textfield
instantiated , name
property assigned string "textfield" same setting instance name.
next shape
object called rectangleshape
instantiated graphically configured simple red rectangle.
next sprite
display object object called buttonsprite
instantiated , textfield
, rectangleshape
display objects added it. sprite
display object container added stage.
finally buttonsprite
display object container's getchildbyname()
method called , returns textfield
display object. the textfield
display object's name property has given getchildbyname()
methods's argument. next returned textfield
object stored in local textfield
object called tf
gives access textfield
.
[update]
the following approach accessing textfield
object via simplebutton
object similar accessing via sprite
object(i don't recommend though):
var textfield:textfield = new textfield(); textfield.name = "textfield"; textfield.mouseenabled = false; var rectangleshape:shape = new shape(); rectangleshape.graphics.beginfill(0xff0000); rectangleshape.graphics.drawrect(0, 0, 100, 25); rectangleshape.graphics.endfill(); var simplebuttonsprite:sprite = new sprite(); simplebuttonsprite.name = "simplebuttonsprite"; simplebuttonsprite.addchild(rectangleshape); simplebuttonsprite.addchild(textfield); var simplebutton:simplebutton = new simplebutton(); simplebutton.upstate = simplebuttonsprite; simplebutton.overstate = simplebuttonsprite; simplebutton.downstate = simplebuttonsprite; simplebutton.hitteststate = simplebuttonsprite; addchild(simplebutton); // local simplebuttonsprite object var sbs:displayobjectcontainer = displayobjectcontainer(simplebutton.upstate); //local textfield object var tf:textfield = textfield(sbs.getchildbyname("textfield")); tf.text = "simple button text ";
Comments
Post a Comment