Untouchable Button

Sorry for the language. I’m ary from Indonesia :slight_smile:
Please help me… :frowning:

I have made ​​a button using the UI Library. However, after the button is on the Corona Simulator, no part of these buttons can be touched and can not be touched. Can you explain what happened?

this is my shortcode of homescreen.lua
 

new = function ()

    print( “HomeScreen Started” )

– ANIMATION SUSPEND

    local tSuspend

    local function onSuspendResume( event )

            if “applicationSuspend” == event.type then

                    tSuspend = system.getTimer()

            elseif “applicationResume” == event.type then

                    – add missing time to tPrevious

                    tPrevious = tPrevious + ( system.getTimer() - tSuspend )

            end

    end

    

    Runtime:addEventListener( “system”, onSuspendResume )

– Creating Display Group

    local localGroup = display.newGroup()

    local buttonGroup = display.newGroup( )

– Function Button

    local myTouchListener = function( event )

        print( "object touched = "…tostring(event.x) )  --‘event.target’ is the touched object

        return true  --prevents touch propagation to underlying objects

    end

– Defining Button Home Sprite –

    local sheetInfo = require(“images.animations.tombolAksara.tombolAksara”) – lua file that Texture packer published

    local HomeButtonSheet = graphics.newImageSheet( “images/animations/tombolAksara/tombolAksara.png”, sheetInfo:getSheet() )

– Home Belajar Button

    bt_belajar = ui.newButton({

        defaultSrc = display.newImage(HomeButtonSheet, sheetInfo:getFrameIndex(“AksaraDasar”)),

        defaultX = 309,

        defaultY = 255,

        overSrc = display.newImage(HomeButtonSheet, sheetInfo:getFrameIndex(“AksaraDasarHover”)),

        overX = 309,

        overY = 255,

          onEvent = myTouchListener,

          id = “tombolBelajar”,

    })

    bt_belajar.anchorX = 0

    bt_belajar.anchorY = 1

    bt_belajar.x = display.contentWidth -200

    bt_belajar.y = display.contentHeight -200

– INSERTING –

    localGroup:insert(buttonGroup)

– DEBUGGING –

    print( display.pixelWidth / display.actualContentWidth )

    return localGroup

end

I’m using Corona Build 2013.2100, Thank you :slight_smile:

I’ve never used the ui. library (it’s old I think). The current Corona version uses the widget library, as in: widget.newButton(…)

So I’d recommend using widget.newButton for starters. Also, I’ve never used the passed in argument “onEvent” (widget.newButton allows that also), but instead use a separate line of code to install the listener, such as:

    bt_belajar:addEventListener(“tap”, myTouchListener)

Note the use of “tap”, instead of touch — touch creates multiple events, tap creates just a single event per button tap (making the listener code more simple).

To sum it up, I’d recommend using the widget library, and adding the listener separately from the button creation call. Best of luck!

Thanks mpappas, I’ve already use widget.newButton but i got same problems as i used ui.newButtons. Can you help me? Please :frowning:

mpappas i found the solution of my problem… :slight_smile:
I just activate Setting V1 Compatibility Mode from config.lua. I got the reference from http://docs.coronalabs.com/guide/graphics/migration_v1.html
Thanks for your help :slight_smile:
 

I’m using Corona Build 2013.2100, Thank you :slight_smile:

I’ve never used the ui. library (it’s old I think). The current Corona version uses the widget library, as in: widget.newButton(…)

So I’d recommend using widget.newButton for starters. Also, I’ve never used the passed in argument “onEvent” (widget.newButton allows that also), but instead use a separate line of code to install the listener, such as:

    bt_belajar:addEventListener(“tap”, myTouchListener)

Note the use of “tap”, instead of touch — touch creates multiple events, tap creates just a single event per button tap (making the listener code more simple).

To sum it up, I’d recommend using the widget library, and adding the listener separately from the button creation call. Best of luck!

Thanks mpappas, I’ve already use widget.newButton but i got same problems as i used ui.newButtons. Can you help me? Please :frowning:

mpappas i found the solution of my problem… :slight_smile:
I just activate Setting V1 Compatibility Mode from config.lua. I got the reference from http://docs.coronalabs.com/guide/graphics/migration_v1.html
Thanks for your help :slight_smile: