on Event does not work? Scene switch with buttons

Hi guys I have a problem with stwitching the scenes through buttons everytime I get an Error at the OnEvent.

If u have a shorter way to programm it pls dont hold it back…

main.lua

local composer = require( "composer" ) display.setStatusBar( display.HiddenStatusBar ) composer.gotoScene( "menue" )

menue.lua

local composer = require( "composer" ) local widget = require("widget") local scene = composer.newScene() -- ----------------------------------------------------------------------------------------------------------------- -- All code outside of the listener functions will only be executed ONCE unless "composer.removeScene()" is called. -- ----------------------------------------------------------------------------------------------------------------- -- local forward references should go here local function gotogamemenue( event ) local sceneGroup = self.view local options = { effect = "fade", time = 800, } composer.gotoScene( "gamemenue", options) end -- ------------------------------------------------------------------------------- -- "scene:create()" function scene:create( event ) local sceneGroup = self.view -- Initialize the scene here. -- Example: add display objects to "sceneGroup", add touch listeners, etc. end -- "scene:show()" function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Called when the scene is still off screen (but is about to come on screen). local background = display.newImage( "background.png" ) local buttonNewGame = widget.newButton { width = 100, height = 100, defaultFile = "add.png", overFile = "addclick.png", onEvent = "gotogamemenue", } buttonNewGame.x = display.contentCenterX / 1 buttonNewGame.y = display.contentCenterY / 1.7 local buttonGalerie = widget.newButton { width = 100, height = 100, defaultFile = "galerie.png", overFile = "galerieclick.png", onEvent = "gotogamemenue", } buttonGalerie.x = display.contentCenterX / 1 buttonGalerie.y = display.contentCenterY / 0.7 elseif ( phase == "did" ) then -- Called when the scene is now on screen. -- Insert code here to make the scene come alive. -- Example: start timers, begin animation, play audio, etc. end end -- "scene:hide()" function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Called when the scene is on screen (but is about to go off screen). -- Insert code here to "pause" the scene. -- Example: stop timers, stop animation, stop audio, etc. elseif ( phase == "did" ) then -- Called immediately after scene goes off screen. end end -- "scene:destroy()" function scene:destroy( event ) local sceneGroup = self.view -- Called prior to the removal of scene's view ("sceneGroup"). -- Insert code here to clean up the scene. -- Example: remove display objects, save state, etc. end -- ------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) -- ------------------------------------------------------------------------------- return scene

gamemenue.lua

local composer = require( "composer" ) local scene = composer.newScene() -- ----------------------------------------------------------------------------------------------------------------- -- All code outside of the listener functions will only be executed ONCE unless "composer.removeScene()" is called. -- ----------------------------------------------------------------------------------------------------------------- -- local forward references should go here -- ------------------------------------------------------------------------------- -- "scene:create()" function scene:create( event ) local sceneGroup = self.view -- Initialize the scene here. -- Example: add display objects to "sceneGroup", add touch listeners, etc. end -- "scene:show()" function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Called when the scene is still off screen (but is about to come on screen). elseif ( phase == "did" ) then -- Called when the scene is now on screen. -- Insert code here to make the scene come alive. -- Example: start timers, begin animation, play audio, etc. end end -- "scene:hide()" function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Called when the scene is on screen (but is about to go off screen). -- Insert code here to "pause" the scene. -- Example: stop timers, stop animation, stop audio, etc. elseif ( phase == "did" ) then -- Called immediately after scene goes off screen. end end -- "scene:destroy()" function scene:destroy( event ) local sceneGroup = self.view -- Called prior to the removal of scene's view ("sceneGroup"). -- Insert code here to clean up the scene. -- Example: remove display objects, save state, etc. end -- ------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) -- ------------------------------------------------------------------------------- return scene

I really would appreciate some help pls…

Greetings Adrian

I don’t think you need quotes around your widget onEvent calls. Try removing those and see if it works.

As Alex says, onEvent should be a callback function, not a string. So fix this:

onEvent = "gotogamemenue",

See the API docs for more info: http://docs.coronalabs.com/api/library/widget/newButton.html

And on top of that, the onEvent is like a touch event, that is there will be an “began” phase and an “ended” phase.  Unless you test for this, your code in onEvent will execute twice.

Rob

Thanks for the realy fast replys :). I changed it to this 

onEvent = gotogamemenue,

I don’t get an error anymore but it is not doing what it shall do. I can click but I think he doesen’t realise what comes next. Or is that the Problem that Rob spoke about? (Where do I set the "began and “end”?)

Adrian

local function gotogamemenue( event )     if event.phase == "ended" then         local options = {             effect = "fade",             time = 800,         }         composer.gotoScene( "gamemenue", options)     end end

Ok thank u so so much all u guys I got it ;* Hope I didn’t enoyed with this   `:)

Adrian

I don’t think you need quotes around your widget onEvent calls. Try removing those and see if it works.

As Alex says, onEvent should be a callback function, not a string. So fix this:

onEvent = "gotogamemenue",

See the API docs for more info: http://docs.coronalabs.com/api/library/widget/newButton.html

And on top of that, the onEvent is like a touch event, that is there will be an “began” phase and an “ended” phase.  Unless you test for this, your code in onEvent will execute twice.

Rob

Thanks for the realy fast replys :). I changed it to this 

onEvent = gotogamemenue,

I don’t get an error anymore but it is not doing what it shall do. I can click but I think he doesen’t realise what comes next. Or is that the Problem that Rob spoke about? (Where do I set the "began and “end”?)

Adrian

local function gotogamemenue( event )     if event.phase == "ended" then         local options = {             effect = "fade",             time = 800,         }         composer.gotoScene( "gamemenue", options)     end end

Ok thank u so so much all u guys I got it ;* Hope I didn’t enoyed with this   `:)

Adrian