Director Class Issue?

I’m trying to add a feature to my app where the user can double tap the screen to get to the menu. I’m using the director class, but it’s not working out for me. Did I do anything wrong?
[lua]local director = require(“director”);

local mainGroup = display.newGroup();
– I put the above code first in my app, then the body, then the following…

local function main ()

mainGroup:insert(director.directorView);

director:changeScene(“Menu”);

return true;

end
local onTap = function(event)

if 2 == event.numTaps then

main();

return true;
end
end

Runtime:addEventListener(“tap”, onTap)
[import]uid: 54001 topic_id: 9309 reply_id: 309309[/import]

I think you will have to create a tap adding up function. eg:
[lua]local taps = 0
local function countTaps(event)
if event.phase == “began” then
taps = taps + 1
end

if taps == 2 then
main()
end

end
Runtime:addEventListener(“tap”, countTaps)

local function main ()

mainGroup:insert(director.directorView);

director:changeScene(“Menu”);

return true;

end[/lua]

Something like this could work? Give it a try anyway. [import]uid: 33866 topic_id: 9309 reply_id: 33969[/import]

Ugh, that doesn’t work either, my app just freezes and says something about assertion. My app is an alarm clock so far…
Argh!

[text]
Runtime error
assertion failed!
stack traceback:
[C]: ?
[C]: in function ‘assert’
?: in function ‘getOrCreateTable’
?: in function ‘addEventListener’
?: in function ‘addEventListener’
…blah\blah\blah\Alarm Clock\Aclock.lua:93: in mRuntime
error: assertion failed!
stack traceback:
[C]: ?
[C]: in function ‘assert’
?: in function ‘getOrCreateTable’
?: in function ‘addEventListener’
?: in function ‘addEventListener’
…blah\blah\blah\Alarm Clock\Aclock.lua:93: in main chun
k
[C]:Runtime error
…blah\blah\blah\Alarm Clock\director.lua:303: ERROR: tabl
e expected. If this is a function call, you might have used ‘.’ instead of ‘:’
stack traceback:
[C]: ?
[C]: in function ‘insert’
…Blah\Blah\Blah\Alarm

[lua]-- line 93
Runtime:addEventListener(“tap”, countTaps)

– line 303 in Director.lua file
currView:insert(currScreen)

[import]uid: 54001 topic_id: 9309 reply_id: 33976[/import]

Your main.lua should be something like below… Note line no 31 below.

[lua]display.setStatusBar( display.HiddenStatusBar )


– Import director class

director = require(“director”)


– Create a main group

local mainGroup = display.newGroup()

– Main function

local function main()


– Add the group from director class

mainGroup:insert(director.directorView)


– Change scene without effects

director:changeScene(“Aclock.lua”)


– Return

return true
end


– Begin

main()

– It’s that easy! :-)[/lua]

Now your Aclock.lua should be like following template.

[lua]module(…, package.seeall)


– GROUPS

local localGroup = display.newGroup()


– DISPLAY OBJECTS

local background = display.newRect(0,0,320,480)
local title = display.newText(“Template”, 0, 0, native.systemFontBold, 16)


– LISTENERS

local function tapped( event )
if 2 == event.numTaps then

director:changeScene(“menu”,“crossfade”);

end
end


– INIT VARS

local function initVars ()


– Inserts

localGroup:insert(background)
localGroup:insert(title)


– Positions

title.x = 160
title.y = 240


– Colors

background:setFillColor(0,200,100)
title:setTextColor( 255,255,255)


– Listeners

background:addEventListener( “tap” , tapped)

end


– CLEAN

function clean ( event )
print(“cleaned”)
end


– NEW

function new()


– Initiate variables

initVars()


– MUST return a display.newGroup()

return localGroup

end[/lua] [import]uid: 48521 topic_id: 9309 reply_id: 34047[/import]

That doesn’t seem to work out well or maybe I did something wrong.

This is my tap function below, I think it should work but I just need an event listener. Do i need anything else in my file from the director class?
[lua]local function changeScene(event)

if (2 == event.numTaps) then

director:changeScene(“menu”)

end
end [import]uid: 54001 topic_id: 9309 reply_id: 34206[/import]