Help me with the switch-widget please!

Hi !

I just want to know how to make the simplest switch by using my own pictures.

I would like it to work like this. (see below)

But is does´nt! So apperently there´s something wrong with this.

Can someon help me with how it should look like?

(Yes i require widgets etc, it´s just my switch code that makes it crash!)
Thank you so much!

[code]
local swtBtn = widget.newSwitch
{

width=300,
height=150,
frameOn=“bild1.png”,
frameOff=“bild2.png”,
onPress=function1,
onRelease=function2,
}

[code]

[import]uid: 197493 topic_id: 36032 reply_id: 336032[/import]

Hi.

As per the documentation: http://docs.coronalabs.com/api/library/widget/newSwitch.html

frameOn & frameOff are frames indexes from an imageSheet which you have created. They are not individual png image files.
[import]uid: 84637 topic_id: 36032 reply_id: 143170[/import]

Thank you!

I solved it myself, but now i have another problem.

I want my spritesheet to start when i hit a button but i cant get it to work.

Any tips for this one :)?

[code]

function knapp1 (event)
instance:play(“hubbe.png”)
end

button1 = widget.newButton{
default = “startknapp.png”,
over = “menyknapp.png”,
onRelease = knapp1,
emboss = true
}
button1.x=_W/2;button1.y=_H/2.2

local sheet2 = graphics.newImageSheet( “hubbe.png”, { width=160, height=200, numFrames=6 } )
local instance = display.newSprite( sheet2, { name=“hubbe.png”, start=1, count=6, time=2000 } )
instance.x =500
instance.y = 500
[import]uid: 197493 topic_id: 36032 reply_id: 143331[/import]

Yes you have a scope issue there.

Your function cannot “see” instance because you have declared it below the function. There are several ways to get around this situation, the most common being creating a “forward reference”.

See the below modified example of your code:

[code]
– Create a “forward reference” to instance here
local instance

function knapp1 (event)
instance:play(“hubbe.png”)
end

button1 = widget.newButton{
default = “startknapp.png”,
over = “menyknapp.png”,
onRelease = knapp1,
emboss = true
}
button1.x=_W/2;button1.y=_H/2.2

local sheet2 = graphics.newImageSheet( “hubbe.png”, { width=160, height=200, numFrames=6 } )

– Create instance here
instance = display.newSprite( sheet2, { name=“hubbe.png”, start=1, count=6, time=2000 } )
instance.x =500
instance.y = 500
[/code] [import]uid: 84637 topic_id: 36032 reply_id: 143334[/import]

Hi.

As per the documentation: http://docs.coronalabs.com/api/library/widget/newSwitch.html

frameOn & frameOff are frames indexes from an imageSheet which you have created. They are not individual png image files.
[import]uid: 84637 topic_id: 36032 reply_id: 143170[/import]

Thank you!

I solved it myself, but now i have another problem.

I want my spritesheet to start when i hit a button but i cant get it to work.

Any tips for this one :)?

[code]

function knapp1 (event)
instance:play(“hubbe.png”)
end

button1 = widget.newButton{
default = “startknapp.png”,
over = “menyknapp.png”,
onRelease = knapp1,
emboss = true
}
button1.x=_W/2;button1.y=_H/2.2

local sheet2 = graphics.newImageSheet( “hubbe.png”, { width=160, height=200, numFrames=6 } )
local instance = display.newSprite( sheet2, { name=“hubbe.png”, start=1, count=6, time=2000 } )
instance.x =500
instance.y = 500
[import]uid: 197493 topic_id: 36032 reply_id: 143331[/import]

Yes you have a scope issue there.

Your function cannot “see” instance because you have declared it below the function. There are several ways to get around this situation, the most common being creating a “forward reference”.

See the below modified example of your code:

[code]
– Create a “forward reference” to instance here
local instance

function knapp1 (event)
instance:play(“hubbe.png”)
end

button1 = widget.newButton{
default = “startknapp.png”,
over = “menyknapp.png”,
onRelease = knapp1,
emboss = true
}
button1.x=_W/2;button1.y=_H/2.2

local sheet2 = graphics.newImageSheet( “hubbe.png”, { width=160, height=200, numFrames=6 } )

– Create instance here
instance = display.newSprite( sheet2, { name=“hubbe.png”, start=1, count=6, time=2000 } )
instance.x =500
instance.y = 500
[/code] [import]uid: 84637 topic_id: 36032 reply_id: 143334[/import]

Hi.

As per the documentation: http://docs.coronalabs.com/api/library/widget/newSwitch.html

frameOn & frameOff are frames indexes from an imageSheet which you have created. They are not individual png image files.
[import]uid: 84637 topic_id: 36032 reply_id: 143170[/import]

Thank you!

I solved it myself, but now i have another problem.

I want my spritesheet to start when i hit a button but i cant get it to work.

Any tips for this one :)?

[code]

function knapp1 (event)
instance:play(“hubbe.png”)
end

button1 = widget.newButton{
default = “startknapp.png”,
over = “menyknapp.png”,
onRelease = knapp1,
emboss = true
}
button1.x=_W/2;button1.y=_H/2.2

local sheet2 = graphics.newImageSheet( “hubbe.png”, { width=160, height=200, numFrames=6 } )
local instance = display.newSprite( sheet2, { name=“hubbe.png”, start=1, count=6, time=2000 } )
instance.x =500
instance.y = 500
[import]uid: 197493 topic_id: 36032 reply_id: 143331[/import]

Yes you have a scope issue there.

Your function cannot “see” instance because you have declared it below the function. There are several ways to get around this situation, the most common being creating a “forward reference”.

See the below modified example of your code:

[code]
– Create a “forward reference” to instance here
local instance

function knapp1 (event)
instance:play(“hubbe.png”)
end

button1 = widget.newButton{
default = “startknapp.png”,
over = “menyknapp.png”,
onRelease = knapp1,
emboss = true
}
button1.x=_W/2;button1.y=_H/2.2

local sheet2 = graphics.newImageSheet( “hubbe.png”, { width=160, height=200, numFrames=6 } )

– Create instance here
instance = display.newSprite( sheet2, { name=“hubbe.png”, start=1, count=6, time=2000 } )
instance.x =500
instance.y = 500
[/code] [import]uid: 84637 topic_id: 36032 reply_id: 143334[/import]

Hi.

As per the documentation: http://docs.coronalabs.com/api/library/widget/newSwitch.html

frameOn & frameOff are frames indexes from an imageSheet which you have created. They are not individual png image files.
[import]uid: 84637 topic_id: 36032 reply_id: 143170[/import]

Thank you!

I solved it myself, but now i have another problem.

I want my spritesheet to start when i hit a button but i cant get it to work.

Any tips for this one :)?

[code]

function knapp1 (event)
instance:play(“hubbe.png”)
end

button1 = widget.newButton{
default = “startknapp.png”,
over = “menyknapp.png”,
onRelease = knapp1,
emboss = true
}
button1.x=_W/2;button1.y=_H/2.2

local sheet2 = graphics.newImageSheet( “hubbe.png”, { width=160, height=200, numFrames=6 } )
local instance = display.newSprite( sheet2, { name=“hubbe.png”, start=1, count=6, time=2000 } )
instance.x =500
instance.y = 500
[import]uid: 197493 topic_id: 36032 reply_id: 143331[/import]

Yes you have a scope issue there.

Your function cannot “see” instance because you have declared it below the function. There are several ways to get around this situation, the most common being creating a “forward reference”.

See the below modified example of your code:

[code]
– Create a “forward reference” to instance here
local instance

function knapp1 (event)
instance:play(“hubbe.png”)
end

button1 = widget.newButton{
default = “startknapp.png”,
over = “menyknapp.png”,
onRelease = knapp1,
emboss = true
}
button1.x=_W/2;button1.y=_H/2.2

local sheet2 = graphics.newImageSheet( “hubbe.png”, { width=160, height=200, numFrames=6 } )

– Create instance here
instance = display.newSprite( sheet2, { name=“hubbe.png”, start=1, count=6, time=2000 } )
instance.x =500
instance.y = 500
[/code] [import]uid: 84637 topic_id: 36032 reply_id: 143334[/import]