Button With Storyboard Question!

I am using storyboard and add my graphics during the createScene event and add my event listeners in the enterScene event. However when adding button widgets I have to add the onEvent when I place the button. Is there a way to add the onEvent = someFunction() to the widget table later in the enterScene event but still create the button in the createScene event?

Thanks for any help!

@Mattgames, I’m not sure why you’d want (or need) to add the onEvent = someFunction() to widget table in the enterScene.  Maybe you need to explain why before someone can come up with a solution that best meets your requirement.  

I use storyboard, and in some of my scenes, I create widget buttons inside the createScene and have onRelease property added at the time I create them.  someFunction() is defined before (i.e., above & outside) the createScene function.  

I do want to dynamically change the function attached to onRelease property, but I don’t have any issue adding the function at the time of creation either.

Naomi

Hi Naomi,

Thanks for the response. Currently I am loading a main screen and then depending on a parameter may need to have an overlay show up before the user is allowed to hit any buttons on this main screen. However the main screen will be visible through the overlay so the buttons all need to be in place. I know that once the overlay is active I can block all hits to the screen underneath but am concerned about accidental hits that occur before the overlay pops up. I guess I could call the overlay at the beginning of my main screen file instead of at the end. Any thought would be appreciated. Thanks!

Ah, okay, here’s a trick I sometimes use when I don’t want any touch event to occur.

  1.  Create a widget button with transparent png file that covers the entire screen, let’s call it btnBlockTouch.

  2.  Attach a function that does nothing but return true.

  3.  Create all scene elements.

  4.  Call btnBlockTouch:toFront()

  5.  Create and show overlay that would come on top of the scene elements

  6.  When you close the overlay, call btnBlockTouch:toBack()

You can also simply create btnBlockTouch immediately after all screen elements are created and not bother with bringing it to front, and remove it when you don’t want it anymore, rather than sending it back.

Another method might be to add .isActive property to buttons on screen, and set it to false until you’re ready for the button to do something.  And the function would only work if .isActive property is true – but if you just want all screen elements to be turned off, this approach may require just a lot more code you don’t need to deal with. 

I’ve never used overlay, so I’m simply assuming that somehow, users can end up touching things behind the overlay… or somehow, you have trouble getting it to appear before users start touching the scene…

I hope this helps anyhow.

Naomi

@Mattgames, I’m not sure why you’d want (or need) to add the onEvent = someFunction() to widget table in the enterScene.  Maybe you need to explain why before someone can come up with a solution that best meets your requirement.  

I use storyboard, and in some of my scenes, I create widget buttons inside the createScene and have onRelease property added at the time I create them.  someFunction() is defined before (i.e., above & outside) the createScene function.  

I do want to dynamically change the function attached to onRelease property, but I don’t have any issue adding the function at the time of creation either.

Naomi

Hi Naomi,

Thanks for the response. Currently I am loading a main screen and then depending on a parameter may need to have an overlay show up before the user is allowed to hit any buttons on this main screen. However the main screen will be visible through the overlay so the buttons all need to be in place. I know that once the overlay is active I can block all hits to the screen underneath but am concerned about accidental hits that occur before the overlay pops up. I guess I could call the overlay at the beginning of my main screen file instead of at the end. Any thought would be appreciated. Thanks!

Ah, okay, here’s a trick I sometimes use when I don’t want any touch event to occur.

  1.  Create a widget button with transparent png file that covers the entire screen, let’s call it btnBlockTouch.

  2.  Attach a function that does nothing but return true.

  3.  Create all scene elements.

  4.  Call btnBlockTouch:toFront()

  5.  Create and show overlay that would come on top of the scene elements

  6.  When you close the overlay, call btnBlockTouch:toBack()

You can also simply create btnBlockTouch immediately after all screen elements are created and not bother with bringing it to front, and remove it when you don’t want it anymore, rather than sending it back.

Another method might be to add .isActive property to buttons on screen, and set it to false until you’re ready for the button to do something.  And the function would only work if .isActive property is true – but if you just want all screen elements to be turned off, this approach may require just a lot more code you don’t need to deal with. 

I’ve never used overlay, so I’m simply assuming that somehow, users can end up touching things behind the overlay… or somehow, you have trouble getting it to appear before users start touching the scene…

I hope this helps anyhow.

Naomi