views:

151

answers:

2

hi every one, 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?

A: 

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"
}
VideoDnd
hi VideoDnd thank you for the response, Sorry if my previous explanation is not good enough, i created a button (button symbol), inside this button symbol there is a vector shape which will change colours in mouse over and a dynamic text field. i want to use this button symbol in more than one locations in my stage. so i need to change the label of these instances (by changing dynamic text ). but i can't access the dynamic text in as3 using following code, btnsample.txtbtnlabel.text = "button label" this code is working fine in a movie clip symbol but not in a button symbol.
sasi350
Do you have any code? Also, my answer had extra code that wasn't necessary, I apologize:)
VideoDnd
This looks right btnsample.txtbtnlabel.text = "button label". Button symbol are a bother. I would use a Movieclip, since you can create all those states without a button symbol.
VideoDnd
+1  A: 

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

sasi350
pretty cool solution.
VideoDnd
thanks, and thank you for your response :)
sasi350