Trouble creating a simple switch

Hi, I am trying to create a simple switch using the code below

local widget = require("widget")  
  
local myTxt = display.newText("Hello", 0, 0, native.systemFontBold, 40)  
myTxt.x = display.screenOriginX + display.viewableContentWidth\*0.5  
myTxt.y = 50  
myTxt:setTextColor(255)  
  
local myBtn = widget.newSwitch {  
 id = "myswitch",  
 width = 50,  
 height = 50,  
 sheet = "btn\_radio\_onoff.png",  
 data = "btn\_radio\_onoff",  
 frameOff = "btn\_radio\_off",  
 frameOn = "btn\_radio\_on",  
 initialSwitchState = false,  
 style = "radio"  
 }  
myBtn.x = display.screenOriginX + display.viewableContentWidth\*0.5  
myBtn.y = display.screenOriginY + display.viewableContentHeight\*0.5  
  

I am using Widget 1.0 on build 1033. It keeps failing with the error shown below

2013-03-11 23:19:36.303 Corona Simulator[18987:f03] Version: 2.0.0  
2013-03-11 23:19:36.303 Corona Simulator[18987:f03] Build: 2013.1033  
2013-03-11 23:19:36.311 Corona Simulator[18987:f03] The file sandbox for this project is located at the following folder:  
 (/Users/shiva.paranandi/Library/Application Support/Corona Simulator/testRadio-39EE1563B5FBE985810075DC147F34EF)  
2013-03-11 23:19:36.314 Corona Simulator[18987:f03] Runtime error  
 ?:0: attempt to index a nil value  
stack traceback:  
 [C]: ?  
 ?: in function <?:453>  
 (tail call): ?  
 /Users/shiva.paranandi/Shiva/testRadio/main.lua:8: in main chunk  
2013-03-11 23:19:36.314 Corona Simulator[18987:f03] Runtime error:   
2013-03-11 23:19:36.315 Corona Simulator[18987:f03] ?:0: attempt to index a nil value  
stack traceback:  
 [C]: ?  
 ?: in function <?:453>  
 (tail call): ?  
 /Users/shiva.paranandi/Shiva/testRadio/main.lua:8: in main chunk  

Any help is highly appreciated.

Thanks. [import]uid: 103483 topic_id: 37573 reply_id: 67573[/import]

Hi. There were some incorrect things in that daily build which have since been rectified.
You are no longer required to pass a “data” parameter and “sheet” must be an imagesheet you have created via graphics.newImageSheet.

Please see the updated docs here: http://docs.coronalabs.com/daily/api/library/widget/newSwitch.html [import]uid: 84637 topic_id: 37573 reply_id: 145798[/import]

Thanks Danny. Do I need to upgrade to 1051 or do your comments apply to build 1033 also? One other in the widget-v1.lua posted on GitHub at https://github.com/coronalabs/widget-v1 does not have the newSwitch code. So I am not sure if I move to a newer build then how can I use the old widgets switch?

Thanks. [import]uid: 103483 topic_id: 37573 reply_id: 145815[/import]

Hey.

You need to upgrade to 1051 ( or 1047 ) yeah.

Widget v-1 doesn’t contain any of the new widgets nor the new widget library (just an fyi)
The switches are a new widget which don’t apply to widget v1

Thanks [import]uid: 84637 topic_id: 37573 reply_id: 145817[/import]

Interesting. I was looking at the docs here http://docs.coronalabs.com/api/library/widget/newSwitch.html and the revision says 2012.971. The Sample code in build 1033 also has code using the newSwitch and the simulator works with it. I don’t want to migrate to 1051 right now as I would have to redo a lot of my widget work. Anyway I can have the switch work in build 1033 as the sample code and the docs show that it is present in 1033. [import]uid: 103483 topic_id: 37573 reply_id: 145824[/import]

It’s not possible I am afraid.

There was a bug in that version that simply made it impossible for it to be customized.
It was released in 971 but it was still using the new widget library, at the time the new widget library was calling the old widget libraries code for the other widgets (like tableViews, scrollViews ) etc.

[import]uid: 84637 topic_id: 37573 reply_id: 145826[/import]

Hi. There were some incorrect things in that daily build which have since been rectified.
You are no longer required to pass a “data” parameter and “sheet” must be an imagesheet you have created via graphics.newImageSheet.

Please see the updated docs here: http://docs.coronalabs.com/daily/api/library/widget/newSwitch.html [import]uid: 84637 topic_id: 37573 reply_id: 145798[/import]

Thanks Danny. Do I need to upgrade to 1051 or do your comments apply to build 1033 also? One other in the widget-v1.lua posted on GitHub at https://github.com/coronalabs/widget-v1 does not have the newSwitch code. So I am not sure if I move to a newer build then how can I use the old widgets switch?

Thanks. [import]uid: 103483 topic_id: 37573 reply_id: 145815[/import]

Hey.

You need to upgrade to 1051 ( or 1047 ) yeah.

Widget v-1 doesn’t contain any of the new widgets nor the new widget library (just an fyi)
The switches are a new widget which don’t apply to widget v1

Thanks [import]uid: 84637 topic_id: 37573 reply_id: 145817[/import]

Interesting. I was looking at the docs here http://docs.coronalabs.com/api/library/widget/newSwitch.html and the revision says 2012.971. The Sample code in build 1033 also has code using the newSwitch and the simulator works with it. I don’t want to migrate to 1051 right now as I would have to redo a lot of my widget work. Anyway I can have the switch work in build 1033 as the sample code and the docs show that it is present in 1033. [import]uid: 103483 topic_id: 37573 reply_id: 145824[/import]

It’s not possible I am afraid.

There was a bug in that version that simply made it impossible for it to be customized.
It was released in 971 but it was still using the new widget library, at the time the new widget library was calling the old widget libraries code for the other widgets (like tableViews, scrollViews ) etc.

[import]uid: 84637 topic_id: 37573 reply_id: 145826[/import]