setTextColor in native.newTextField()

Hi, i need use native.newTextField() in my project and i want set color of input text.

https://docs.coronalabs.com/api/type/TextField/setTextColor.html this is an example, but if 

i use method setTextColor, Corona return error : “attemp to call method “setTextColor” (a nil value)”

What is wrong please ??

here is my code : 

  username = native.newTextField( nx/2+55, 750+n, 590, 100 )

  username.font = native.newFont( native.systemFontBold, 48)

  username.text = “”

  username.hasBackground = false

  username:addEventListener( “userInput”, onUsername )

  username : setTextColor(1,1,1)

I tried your code and didn’t get any errors. What build are you running? I only got an error on the listener because i didn’t have the function. So i put this together. 

Put this code in your file and save it. Not when you click anywhere on the screen the testField will pop up and now when you type you will have red letters.

local centerX = display.contentCenterX local centerY = display.contentCenterY local function onUsername(event) if event.phase == "ended" then local username = native.newTextField( centerX, centerY, 200, 100 ) username.font = native.newFont( native.systemFontBold, 48) username.text = "" username.hasBackground = false username:setTextColor(1,0,0) Runtime:removeEventListener( "touch", onUsername ) end end Runtime:addEventListener( "touch", onUsername )

–SonicX278 

I dont know what is wrong. I build in last stable version 2016.2830 and i try this also in old version 2015.2755 with

same error :frowning:

I work in Windows 10 and build for Android

Have you tried the example above in a new project? Try it and report back with the results.

–SonicX278 

Hm. If i tested only example in a new project all is ok. But in my project everything works fine until i use this “setTextColor”… ?

It may be that it is not in my main.lua but in the module? Something needs to be set up?

Can you post the code where you press to get the text field to show up please?

–SonicX278

It is essentially a example code from API documentation :

local function onUsername( event )

    if ( “began” == event.phase ) then

    elseif ( “submitted” == event.phase ) then

        native.setKeyboardFocus( password )

    end

end

local function onPassword( event )

    if ( “submitted” == event.phase ) then

        native.setKeyboardFocus( nil )

    end

end

function getPassword()  – obrazovka pro zadání jména a hesla

  status = “login”

  backpass = display.newImage(img…“back.png”)

  backpass.anchorX = 0.5    backpass.anchorY = 0

  backpass.xScale = 1.2 backpass.yScale = 1.2

  backpass.x = nx/2 backpass.y = -150

  

  n = 100

  username = native.newTextField( nx/2+55, 750+n, 590, 100 )

  username.font = native.newFont( native.systemFontBold, 48)

  username.text = “”

  username.hasBackground = false

  username:addEventListener( “userInput”, onUsername )

  username : setTextColor(1,1,1)

  password = native.newTextField( nx/2+55, 900+n, 590, 100 )

  password.font = native.newFont( native.systemFontBold, 48 )

  password.text = “”

  password.isSecure = true

  password.hasBackground = false

  password:addEventListener( “userInput”, onPassword )

  usericon = display.newImage(img…“iconUser_blue.png”)

  usericon.anchorX = 0   usericon.anchorY = 0.5

  usericon.x = nx/2-323 usericon.y = 750+n

  

  passicon = display.newImage(img…“iconLock_blue.png”)

  passicon.anchorX = 0   passicon.anchorY = 0.5

  passicon.x = nx/2-317 passicon.y = 900+n

  

  button = display.newRect(nx/2,1070+n,700,100)

  button:setFillColor(0.3, 0.3, 0.3)

  button.alpha = 0.1

  buttontext = display.newText(“LOGIN”,nx/2,1070+n,myFontBold,48)

  buttontext : setTextColor(0.6, 0.6, 0.6)

  button : addEventListener(“tap”,testPass)

end  

At your instigation that I am tested separately, and everything works. I’m beginning to be unhappy

I have no idea what that might influence

RESOLVED !! info for everyone:

I used the foundation of your old project to save job and a problem made this statement that he probably does not :

if “Win” == system.getInfo( “platformName” ) then require(“win_fix”) end

Thank you mutch SonicX278 for your interest.

I tried your code and didn’t get any errors. What build are you running? I only got an error on the listener because i didn’t have the function. So i put this together. 

Put this code in your file and save it. Not when you click anywhere on the screen the testField will pop up and now when you type you will have red letters.

local centerX = display.contentCenterX local centerY = display.contentCenterY local function onUsername(event) if event.phase == "ended" then local username = native.newTextField( centerX, centerY, 200, 100 ) username.font = native.newFont( native.systemFontBold, 48) username.text = "" username.hasBackground = false username:setTextColor(1,0,0) Runtime:removeEventListener( "touch", onUsername ) end end Runtime:addEventListener( "touch", onUsername )

–SonicX278 

I dont know what is wrong. I build in last stable version 2016.2830 and i try this also in old version 2015.2755 with

same error :frowning:

I work in Windows 10 and build for Android

Have you tried the example above in a new project? Try it and report back with the results.

–SonicX278 

Hm. If i tested only example in a new project all is ok. But in my project everything works fine until i use this “setTextColor”… ?

It may be that it is not in my main.lua but in the module? Something needs to be set up?

Can you post the code where you press to get the text field to show up please?

–SonicX278

It is essentially a example code from API documentation :

local function onUsername( event )

    if ( “began” == event.phase ) then

    elseif ( “submitted” == event.phase ) then

        native.setKeyboardFocus( password )

    end

end

local function onPassword( event )

    if ( “submitted” == event.phase ) then

        native.setKeyboardFocus( nil )

    end

end

function getPassword()  – obrazovka pro zadání jména a hesla

  status = “login”

  backpass = display.newImage(img…“back.png”)

  backpass.anchorX = 0.5    backpass.anchorY = 0

  backpass.xScale = 1.2 backpass.yScale = 1.2

  backpass.x = nx/2 backpass.y = -150

  

  n = 100

  username = native.newTextField( nx/2+55, 750+n, 590, 100 )

  username.font = native.newFont( native.systemFontBold, 48)

  username.text = “”

  username.hasBackground = false

  username:addEventListener( “userInput”, onUsername )

  username : setTextColor(1,1,1)

  password = native.newTextField( nx/2+55, 900+n, 590, 100 )

  password.font = native.newFont( native.systemFontBold, 48 )

  password.text = “”

  password.isSecure = true

  password.hasBackground = false

  password:addEventListener( “userInput”, onPassword )

  usericon = display.newImage(img…“iconUser_blue.png”)

  usericon.anchorX = 0   usericon.anchorY = 0.5

  usericon.x = nx/2-323 usericon.y = 750+n

  

  passicon = display.newImage(img…“iconLock_blue.png”)

  passicon.anchorX = 0   passicon.anchorY = 0.5

  passicon.x = nx/2-317 passicon.y = 900+n

  

  button = display.newRect(nx/2,1070+n,700,100)

  button:setFillColor(0.3, 0.3, 0.3)

  button.alpha = 0.1

  buttontext = display.newText(“LOGIN”,nx/2,1070+n,myFontBold,48)

  buttontext : setTextColor(0.6, 0.6, 0.6)

  button : addEventListener(“tap”,testPass)

end  

At your instigation that I am tested separately, and everything works. I’m beginning to be unhappy

I have no idea what that might influence

RESOLVED !! info for everyone:

I used the foundation of your old project to save job and a problem made this statement that he probably does not :

if “Win” == system.getInfo( “platformName” ) then require(“win_fix”) end

Thank you mutch SonicX278 for your interest.