Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Trouble creating a simple switch
Started by shivapp Mar 11 2013 10:27 PM

5 replies to this topic
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

shivapp

[GLOBAL: userInfoPane.html]
shivapp
  • Enthusiast

  • 40 posts
  • Corona SDK

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.
uid: 103483 topic_id: 37573 reply_id: 67573


[TOPIC: post.html]
#2

Danny

[GLOBAL: userInfoPane.html]
Danny
  • Corona Geek

  • 2,597 posts
  • Corona Staff

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
uid: 84637 topic_id: 37573 reply_id: 145798


[TOPIC: post.html]
#3

shivapp

[GLOBAL: userInfoPane.html]
shivapp
  • Enthusiast

  • 40 posts
  • Corona SDK

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.
uid: 103483 topic_id: 37573 reply_id: 145815


[TOPIC: post.html]
#4

Danny

[GLOBAL: userInfoPane.html]
Danny
  • Corona Geek

  • 2,597 posts
  • Corona Staff

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
uid: 84637 topic_id: 37573 reply_id: 145817


[TOPIC: post.html]
#5

shivapp

[GLOBAL: userInfoPane.html]
shivapp
  • Enthusiast

  • 40 posts
  • Corona SDK

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.
uid: 103483 topic_id: 37573 reply_id: 145824


[TOPIC: post.html]
#6

Danny

[GLOBAL: userInfoPane.html]
Danny
  • Corona Geek

  • 2,597 posts
  • Corona Staff

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.

uid: 84637 topic_id: 37573 reply_id: 145826



[topic_controls]
[/topic_controls]