how can i change texts in the dynamic textFields in SimpleButton instance (button symbol)?

自闭症网瘾萝莉.ら 提交于 2020-01-05 05:35:08

问题


this may be a basic thing, but i couldn't find an answer by serching internet.

I have created a simple button - Istance name = "btnsample"

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?


回答1:


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";



回答2:


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"
}


来源:https://stackoverflow.com/questions/2780879/how-can-i-change-texts-in-the-dynamic-textfields-in-simplebutton-instance-butto

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!