widget.newButton problem in composer

I will try and explain my issue as best i can for you. When i push button1 it moves to the next scene just fine but the button dose not move in and out which gives the illusion it is moving. Now button2 dose move and its the same code but it is not linked to another scene yet. Button1 dose move if i disable the line of code that links it to the next scene ( button1.touch = onSceneTouch ). I hope i have explained it well enough and i will add some code to help. Thanks

local widget = require( “widget” )

    local button1 = widget.newButton

{

defaultFile = “images/btn1.png”,

overFile = “images/btn1Over.png”,

}

button1.x, button1.y = display.contentWidth * 0.5, 130

button1.xScale = 0.60; button1.yScale = 0.45;

sceneGroup:insert( button1 )

local function onSceneTouch( self, event )

if event.phase == “began” then

composer.gotoScene( “next”, “crossFade”, 1000  )

return true

  end

    end

     button1.touch = onSceneTouch

local button2 = widget.newButton

{

defaultFile = “images/btn2.png”,

overFile = “images/btn2Over.png”,

}

button2.x, button2.y = display.contentWidth * 0.5, 280

button2.xScale = 0.60; button2.yScale = 0.45;

sceneGroup:insert( button2 )

end

Widget button’s cannot be setup to handle events like you are doing.  You’re going to have to restructure your code:

local widget = require( "widget" )   local function onSceneTouch( event )     if event.phase == "began" then         composer.gotoScene( "next", "crossFade", 1000  )     end     return true end   local button1 = widget.newButton {     defaultFile = "images/btn1.png",     overFile = "images/btn1Over.png",     onEvent = onSceneTouch }   button1.x, button1.y = display.contentWidth \* 0.5, 130 button1.xScale = 0.60; button1.yScale = 0.45; sceneGroup:insert( button1 )  

They don’t use table listeners, only function listeners and the address of that listener has to be provided to the creator for the widget.

Rob

Thanks Rob that was a big help. Just one more thing, to have other buttons on the same screen change to different scenes can i use  onSceneTouch1, onSceneTouch2 and so on.

You can.  You can also give the button an “id”, basically a string which could be your sceneName and just use one handler.  But in general I think it’s cleaner to have one function one button.  Its a little more code but it’s clearer as to what  you’re doing.

Rob

Thanks again.

Widget button’s cannot be setup to handle events like you are doing.  You’re going to have to restructure your code:

local widget = require( "widget" )   local function onSceneTouch( event )     if event.phase == "began" then         composer.gotoScene( "next", "crossFade", 1000  )     end     return true end   local button1 = widget.newButton {     defaultFile = "images/btn1.png",     overFile = "images/btn1Over.png",     onEvent = onSceneTouch }   button1.x, button1.y = display.contentWidth \* 0.5, 130 button1.xScale = 0.60; button1.yScale = 0.45; sceneGroup:insert( button1 )  

They don’t use table listeners, only function listeners and the address of that listener has to be provided to the creator for the widget.

Rob

Thanks Rob that was a big help. Just one more thing, to have other buttons on the same screen change to different scenes can i use  onSceneTouch1, onSceneTouch2 and so on.

You can.  You can also give the button an “id”, basically a string which could be your sceneName and just use one handler.  But in general I think it’s cleaner to have one function one button.  Its a little more code but it’s clearer as to what  you’re doing.

Rob

Thanks again.