Execution Error on orientationChanged message

The place to discuss anything and everything about running your LiveCode on Android

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
daryl
Posts: 47
Joined: Mon Apr 29, 2013 11:43 pm

Execution Error on orientationChanged message

Post by daryl » Fri Jun 28, 2013 10:23 pm

Folks,

I'm working with a Galaxy 2 tablet and trying to learn about device orientation. I added the following message handler as described in the dictionary:

on orientationChanged
put mobileDeviceOrientation() into theOrientation
updateInteface theOrientation -- update the interface to fit the new orientation
answer "Orientation is:" && theOrientation
end orientationChanged

and now I am getting the error: Execution Error on orientationChanged in an alert box.

The event handler is in the card that is being displayed.

Any help would be greatly appreciated.

Thanks,

Daryl

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Execution Error on orientationChanged message

Post by Mark » Sat Jun 29, 2013 1:10 am

Hi Daryl,

I suspect there's a typo in the documentation. Inteface should probably interface. Does that solve the problem?

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7389
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Execution Error on orientationChanged message

Post by jacque » Sat Jun 29, 2013 8:59 pm

There is a misspelling in the dictionary and I think it should be "updateInterface" too, but that wouldn't cause the error. It's a cusom handler name that isn't included in the short example, so it could be called anything.

The error is more likely that daryl's script doesn't have a handler named "updateInterface" or even "updateInteface".
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

daryl
Posts: 47
Joined: Mon Apr 29, 2013 11:43 pm

Re: Execution Error on orientationChanged message

Post by daryl » Mon Jul 01, 2013 6:02 pm

Hi Jacque and Mark and thanks for your replies. Both of you were right, once I added the updateInterface handler the error message stopped and the tablet display actually changes to the correct orientation. However I'm still having a problem during startup in that whatever way I am holding the tablet LiveCode reports it as being in portrait mode, and for example the splash screen gets displayed in the wrong orientation. I there some way to have LiveCode check the initial orientation on startup? I am checking if the environment setting in the Mainstack's preOpenCard handler and if it's mobile I then set the allowed orientations using mobileSetAllowedOrientations. I have put the orientationChanged handler in the Mainstack, as well as the splash screen card and the main card that gets displayed at the end of the startup process, but the initial display is always in portrait mode, regardless of the tablet's orientation. I am testing this on a Galaxy tablet tethered to my desktop via a usb connection, in case that makes any difference.

Thanks again,

Daryl

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Execution Error on orientationChanged message

Post by Mark » Thu Jul 04, 2013 11:38 am

Hi Daryl,

The splash screen is displayed before any scripts run. Therefore you can't adjust its orientation by script. You can only change the initial orientation in the standalone application settings window.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7389
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Execution Error on orientationChanged message

Post by jacque » Fri Jul 05, 2013 8:35 pm

Mark's reply is correct for iOS, which shows the splash before the app loads, but since Android doesn't support separate splash screens, you have more options there. Since you're using the first card of your stack as a fake splash screen, all the normal messages will be sent and scripts can respond to them.

You can create two images on that card, one of which is rotated 90 degrees for a landscape display. Check the orientation in a preOpenCard handler in the first card (use mobileOrientation() to get that) and show the correct image. Hide the one that isn't being used. If you get an "upside down" orientation, you can rotate the correct image in the same handler if you want to go that far.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

daryl
Posts: 47
Joined: Mon Apr 29, 2013 11:43 pm

Re: Execution Error on orientationChanged message

Post by daryl » Fri Jul 05, 2013 9:16 pm

Mark and Jacque,

Thanks for your replies. I have commented out the "go to splashcreen card" in the mainstack's on OpenStack, and put in the following:

put mobileOrientation() into tOrientation
answer "the orientations is" && tOrientation

as the very first statement in the on OpenStack of the mainstack script. Unfortunately the answer is always portrait no matter which way I hold the tablet.
After the script goes to the main display card, the on orientationChanged handler does report the correct orientation.

I'm just not sure if this is expected behavior, or what....

Regards,

Daryl

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7389
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Execution Error on orientationChanged message

Post by jacque » Fri Jul 05, 2013 10:10 pm

It isn't what I'd expect, but I haven't actually had time to test it. Querying orientation on openstack may be too early in the sequence though, which is why I suggested using a preOpenCard handler in the script of the first card. You can leave your original openstack handler in place if you want, though strictly speaking you don't need it at all if the first card is the splash, because stacks always open to the first card by default.

If it doesn't work in preOpenCard, then try sending the query in a short amount of time:

on preOpenCard
send "setupOrientationSplash" to me in 1 millisecond
end preOpenCard

on setupOrientationSplash
answer "orientation is:" && mobileOrientation()
end setupOrientationSplash

If that still doesn't work, I'd classify it as a bug because all messaging should be functional by then. What do you get if you just add a button to the first card that responds with the orientation?
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

daryl
Posts: 47
Joined: Mon Apr 29, 2013 11:43 pm

Re: Execution Error on orientationChanged message

Post by daryl » Fri Jul 05, 2013 11:04 pm

Hi Jaques, Based on your response I'm starting to think this is indeed a bug. I put in the timed send command and still got the wrong orientation from mobileOrientation(). I increased the time over several iterations until I got to 1 second with the same result.

If you get some time, could you try to duplicate the problem on your end? If you get the same result, I will file a bug report.

Thanks,

Daryl

sgilito
Posts: 6
Joined: Thu Jan 05, 2012 4:46 pm

Re: Execution Error on orientationChanged message

Post by sgilito » Thu Jul 18, 2013 7:28 pm

Hi,

I'm using the following code:

on OrientationChanged
mobileUnlockOrientation
answer "Orientation:" & mobileDeviceOrientation() & " Locked:" & mobileOrientationLocked() with "Ok"
end OrientationChanged

This code send the correct massage for each orientation, but my card layout remains in portrait mode.

I'm looking the way to change the card layout to to the device orientation.

Any idea about it?

Sgil

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7389
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Execution Error on orientationChanged message

Post by jacque » Thu Jul 18, 2013 7:55 pm

The orientationChanged message is sent before the screen actually changes; it tells you that the screen is ready to change. The resizeStack message is sent after the rotation is complete. So to change your layout, do it in a resizeStack handler.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: Execution Error on orientationChanged message

Post by Dixie » Thu Jul 18, 2013 7:59 pm

try using something like this...

Code: Select all

on orientationChanged
   
end orientationChanged

on resizeStack
   if "portrait" is among the words of iphoneDeviceOrientation() then
      /*do stuff here */
      exit resizeStack
   end if
   
   if "landscape" is among the words of iphoneDeviceOrientation() OR "face" is among the words of iphoneDeviceOrientation() then
      /*do stuff here */
   end if
end resizeStack

Post Reply