this may be a basic thing, but i couldn't find an answer by serching internet.
I have created a simple button - Istance name = "btnsa开发者_Python百科mple"
and there are two layers
layer 0- button design with rollovers - layer 1- dynamic text field - instance name = "txtbtnlabel"
btnsample.txtbtnlabel.text = "new button label;
but it's giving followin error :-119:Access of possible undefined propety txtbtnlabel through a reference with static type flash.display:simpleButton.
how to solve this problem?
I found a solution for this issue, but i don't know wether this is a perfect method or not, but it's working fine.
solution: -
create a simple button and place a dynamic text field and skip the instant name for this field. you can access this dynamic text by index number.
but if you have any visual effects on mouse overs then you need to assign the button label to all those stages in as3.
code:
//-----mous Up ----
var samplebtn_doc:DisplayObjectContainer = samplebtn.upState as DisplayObjectContainer;
var labelsamplebtn:TextField = samplebtn_doc.getChildAt(1) as TextField;
labelsamplebtn.text = "new button label";
//-----mous Over ----
var samplebtn_over:DisplayObjectContainer = samplebtn.overState as DisplayObjectContainer;
var labelsamplebtn_over:TextField = samplebtn_over.getChildAt(1) as TextField;
labelsamplebtn_over.text = "new button label";
//-----mous Down ----
var samplebtn_down:DisplayObjectContainer = samplebtn.downState as DisplayObjectContainer;
var labelsamplebtn_down:TextField = samplebtn_down.getChildAt(1) as TextField;
labelsamplebtn_down.text = "new button label";
Without seeing your code or having a clear explanation, this is my best guess. I hope this helps.
Swap Text Button
//Event listener
btnsample.addEventListener(MouseEvent.CLICK, buttonClick, false, 0, true);
//Button text
btnsample.txtbtnlabel.text = "button label"
//Swap text
function buttonClick(event:MouseEvent):void{
btnsample.txtbtnlabel.text = "new button label"
}
精彩评论