Can't change newButton tex color. Please help

I created a button using ui.lua as shown below. It works fine, however, I can’t seem to figure out how to change the button textcolor later in the program.

button1 = ui.newButton{
default = “btnBlueMedium.png”,
over = “btnBlueMediumOver.png”,
onPress = textFieldButtonPress,
text = “Hello”,
textColor = { 240, 240, 90, 255 },
size = 16,
emboss = true
}

Does anyone know how to change the text color for the button later in the program? I tried everything. Nothing seems to work. Here’s what I tried:

button1:setTextColor(255,255,255)

button1.setTextColor(255,255,255)

button1:textcolor (255, 255, 255)

button1.textColor(255,255,255)

Any help would be appreciated. Thanks.

[import]uid: 104131 topic_id: 18474 reply_id: 318474[/import]

Hey there, do this;

[lua]button1.text:setTextColor(0,0,0)[/lua]

That should work!

Peach :slight_smile: [import]uid: 52491 topic_id: 18474 reply_id: 70956[/import]

Thanks Peach. I have a new problem related to the same topic.

I have a button and want to check if it’s empty (i.e if it has a blank space). If it is empty, I would like to make it invisible. If not I would like to make it visible and set it’s text to “B”. I thought the code below was going to work, however it does. I am doing anything wrong? Thanks for your help.

local button1Press = function( event )

if (button1.text==" ")then
button1.isVisible = false
else
button1.isVisible = true
button1.text (“B”)

end
end

button1 = ui.newButton{
defaultSrc = “images/BVC_ORANGE_3540.png”,
overSrc = “images/BVC_ORANGE_3540.png”,
defaultX = 35, – this is the x coordinate of the button
defaultY = 40,
overX = 35,
overY = 40,
–onEvent = button1Release,
onPress = button1Press,
onRelease = button1Release,
id = “button1”,
text = “”,
font = “Arial”,
textColor = { 51, 51, 51, 255 },
align = “left”,
size = 22,
}

button1.x=50
button1.y=60
Lastly can you please tell me how to disable and enable this function within? Thanks again for your help. [import]uid: 104131 topic_id: 18474 reply_id: 71792[/import]

Hey there,

I’m afraid I can’t test/troubleshoot the entire function or its implementation for you but I CAN tell you how to change the text correctly.

Rather than button1.text = (“B”) do this;
[lua]button1:setText(“B”)[/lua]

Peach :slight_smile: [import]uid: 52491 topic_id: 18474 reply_id: 71811[/import]

Hi Peach,

This has been driving me nuts today too as I also can’t get my button text to change color. I can set the color just fine when I create the button, but I have a picker that updates the text of the button when the user clicks done for the picker. It updates the text just fine, but I can’t get it to update the text color, alignment, or anything else.

bSelectVehicle:setLabel("hi")  
bSelectVehicle.text:setTextColor(0,0,0)  

The above gives me a runtime error:
[bash]
10/11/12 2:17:34.809 PM Corona Simulator[96320]: Runtime error
/Users/dongeraldo/SnakeHead/AutoRev/contactUs.lua:58: attempt to index field ‘text’ (a nil value)
[/bash]

I’ve also tried the following, which doesn’t work, but at least I don’t get a runtime error.

bSelectVehicle:setLabel("hi")  
bSelectVehicle.setTextColor(0,0,0)  

I’m using build 931.
[import]uid: 64538 topic_id: 18474 reply_id: 127137[/import]

Hi Peach,

This has been driving me nuts today too as I also can’t get my button text to change color. I can set the color just fine when I create the button, but I have a picker that updates the text of the button when the user clicks done for the picker. It updates the text just fine, but I can’t get it to update the text color, alignment, or anything else.

bSelectVehicle:setLabel("hi")  
bSelectVehicle.text:setTextColor(0,0,0)  

The above gives me a runtime error:
[bash]
10/11/12 2:17:34.809 PM Corona Simulator[96320]: Runtime error
/Users/dongeraldo/SnakeHead/AutoRev/contactUs.lua:58: attempt to index field ‘text’ (a nil value)
[/bash]

I’ve also tried the following, which doesn’t work, but at least I don’t get a runtime error.

bSelectVehicle:setLabel("hi")  
bSelectVehicle.setTextColor(0,0,0)  

I’m using build 931.
[import]uid: 64538 topic_id: 18474 reply_id: 127137[/import]