Skip to main content
Inspiring
August 25, 2011
Question

Why can't I add touch events to objects?

  • August 25, 2011
  • 2 replies
  • 2129 views

Me again.

I have been posting this question in different forms (including in the Adobe Bug Base) for several months but haven't been able to elicit a helpful response so I'm going to put the question at it's most basic in hopes of finding something out.

I have written an app that assigns touch events to sprites (movie clips). When testing the app on the computer it works just fine. But when I transfer it to the iPad the touch events disappear. Some of them work, and some of them don't. Adobe's responses haven't been able to help and they basically told me that objects can't hold touch events, that all touch events need to be assigned to the stage. However, even Adobe admits that doesn't make any sense for my app and they can't tell me how to make it work.

What I don't understand:

(a) This is an object oriented language and a touch environment. Why can't I assign touches to objects?

(b) How on earth does anyone actually get any app to work if touch events don't work on objects?

I feel like my problem probably has a very simple solution and I've invested hundreds of dollars in order to program this app in a familiar environment (upgrading to a version of flash that had the iOS compiler) and now it turns it it doesn't even work. I'm starting to learn Xcode but I'm really holding out hope. The way I see it, either

(a) I am missing something inherently fundamental about this language, or

(b) Adobe made a grievous oversight in the compiler.

I'm putting my money on A and yet after several months I still have not been able to get anyone to tell me what exactly I'm doing wrong.

I won't be tedious and link to my other forums here, but the bug base ID is 2940816.

Thanks
Amber

This topic has been closed for replies.

2 replies

AmbariAuthor
Inspiring
August 29, 2011

I am going to copy and paste this answer into all of the forums I've asked this question in case some noob like me comes along and needs the answer.

I found the problem! After 3 months I finally figured out what was wrong and why my app was working in Device Central when exported as Flash 10.1 and not on my iPad when exported as AIR for iOS.

The problem is that in the Flash runtime, if a line of code returns a bug, the flash runtime says "Error, shmerror, try again next time." So I had one if, else statement that was executing when it wasn't supposed to be - only once, at the very beginning of the program. It was throwing an error. When I exported as Flash, flash didn't care, and still executed the code later when it was supposed to. But Apple won't let their programs crash. So instead of just trying that code again, Apple decided, after the first error was thrown, that it would then COMPLETELY IGNORE that line of code. So the error was in the line where the states would unhighlight themselves. Apple just shut down that line of code, that's why it wouldn't execute properly.

I ended up changing this line of code

if (lastObjOver != null && lastObjOver.isLocked == true)

which threw an error when the piece was FIRST dragged over the puzzle, to to this

if (lastObjOver.parent != null && lastObjOver.isLocked == true)

which wouldn't throw the error.

Problem solved!

If anyone else is having this problem, I suggest you do what I did. Change all your touch events to mouse events so you can run the program in the adc debugger. That's when I discovered the error being thrown.

Colin Holgate
Inspiring
August 25, 2011

Your question here, and your bug report, are a bit abstaract, especially without the source files. Are you able to break it down to a simple question, like, I touch something and the touch event doesn't happen?

Something useful to lknow, mouse events work fine, and in some cases they seem to succeed better than touch events.

Inspiring
August 25, 2011

Colin Holgate wrote:

Something useful to lknow, mouse events work fine, and in some cases they seem to succeed better than touch events.

And according to the docs:

"Register for MouseEvent events instead of TouchEvent events when possible. MouseEvent events use less processor overhead than TouchEvent events."