problem with ui.newButton

I’m trying to add a Facebook button so that when a player finishes a game he/she can brag about it on FB. I’ve tried the example from Michelles new book which works fine, but when I try to add it to my code I get the following error in the terminal…

Runtime error  
 /Users/home/Desktop/StopIt Solo/ui.lua:124: attempt to index local 'button' (a nil value)  
stack traceback:  
 [C]: ?  
 /Users/home/Desktop/StopIt Solo/ui.lua:124: in function 'newButton'  
 /Users/home/Desktop/StopIt Solo/ipad.lua:845: in function '\_listener'  
 ?: in function <?:514>  
 ?: in function <?:215>  

The only thing I can think of is that my code uses Director, while the original doesn’t.

The top of my code I have the following…
[lua]module(…, package.seeall)

function new()
local localGroup = display.newGroup()
require “sprite”
facebook=require(“facebook”)
json = require(“json”)
ui=require(“ui”)[/lua]

and further down in my show_results function (where the error occurs)…
[lua] fb_btn=ui.newButton{
defaultSrc=“gfx/facebook.png”,
defaultX=64,
defaultY=64,
overSrc=“gfx/facebook_over.png”,
overX=64,
overY=64,
onEvent=onFBTouch,
}
fb_btn.y=850
fb_btn.x=_w/3[/lua]
Any help at all would be greatly appreciated. [import]uid: 7841 topic_id: 26104 reply_id: 326104[/import]

Which version of ui you are using? I use 1.5 which works very well for me…
And on a side not, why don’t you use widget.newButton?
It is the method provided by Ansca

[lua]widget = require “widget”
fb_btn=widget.newButton{
default=“gfx/facebook.png”,
over=“gfx/facebook_over.png”,
width=64,
height=64,
onEvent=onFBTouch,
}
fb_btn.y=850
fb_btn.x=_w/3[/lua]

The only disadvantage of using widget.newButton is yuo cannot specify difference sizes for ordinay and onClick images. [import]uid: 64174 topic_id: 26104 reply_id: 105714[/import]

Oooh thank you! That’s done the trick. Now I just have to work out why after it’s logged you into facebook and asked for permission to post, it doesn’t return to the app or post anything :slight_smile:
[import]uid: 7841 topic_id: 26104 reply_id: 105719[/import]