My button does not work with TouchEvent
Posted: 19 May 2008 03:39 PM   [ Ignore ]
RankRank
Joined  2008-03-11
Total Posts:  138
Jr. Member

Hi, I’m trying to use a simple back button in AppLoader but it wont respond to TouchEvents. I’m fairly sure I have imported the necessary classes, flash.events.*; twice. but I get the following error:

TypeError: Error #1034: Type Coercion failed: cannot convert flash.events::TouchEvent@32e3629 to flash.events.MouseEvent.
at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.events::TUIOObject/flash.events::notifyRemoved()
at flash.events::TUIO$/::processMessage()
at flash.events::TUIO$/::dataHandler()
Can anybody help? I need it to work by tomorrow !!!

 Signature 

~ myHead.addEventListener(Event.ENTER_FRAME, functionProperly); ~

Profile
 
 
Posted: 19 May 2008 04:47 PM   [ Ignore ]   [ # 1 ]
Rank
Joined  2007-10-23
Total Posts:  87
New Member

The error tells you that you are trying to set a TouchEvent to a variable with type MouseEvent. It’s probably the function that responds to the TouchEvent listener, so instead of buttonPressed(evnt:MouseEvent) for example as I supsect you have, you need buttonPressed(evnt:TouchEvent)

Profile
 
 
Posted: 19 May 2008 04:49 PM   [ Ignore ]   [ # 2 ]
RankRank
Joined  2008-03-11
Total Posts:  138
Jr. Member

Absolutety right weyforth! It is always something simple. My excuse is that I am tired....

Thanks for the reply though grin

 Signature 

~ myHead.addEventListener(Event.ENTER_FRAME, functionProperly); ~

Profile
 
 
Posted: 19 May 2008 04:51 PM   [ Ignore ]   [ # 3 ]
Rank
Joined  2007-10-23
Total Posts:  87
New Member

No problem mate I know what it’s like!

EDIT: Just a tip, if you’re using flash which I supsect you are, you can launch the application using the debugger (press ctrl+shift+enter). Then if any errors occur like the one you had it should jump to the line in your code where the problem occurs, shown by a little yellow arrow on the left.

Profile
 
 
Posted: 19 May 2008 05:23 PM   [ Ignore ]   [ # 4 ]
RankRank
Joined  2008-03-11
Total Posts:  138
Jr. Member

Blimey I didn’t know that! Thanks m8grin

 Signature 

~ myHead.addEventListener(Event.ENTER_FRAME, functionProperly); ~

Profile
 
 
Posted: 19 May 2008 05:45 PM   [ Ignore ]   [ # 5 ]
Avatar
RankRankRankRankRankRank
Joined  2007-04-08
Total Posts:  2293
Moderator

another quick tip,

if you want to avoid that error and use both mouse and touch events within the same function, use: functionName(e:Event). Then inside the function you can put

if (e is Touchevent){ do whatever....}
if (e is MouseEvent){do whatever else...}

 Signature 

Follow me on:
My Website - Youtube - Twitter - Linkedin

Profile
 
 
Posted: 19 May 2008 05:48 PM   [ Ignore ]   [ # 6 ]
RankRank
Joined  2008-03-11
Total Posts:  138
Jr. Member

Thanks cerupcat.

Now that I’ve got it to respond, I cant figure out how to unload the current .swf (I’m using it on appLoader)

 Signature 

~ myHead.addEventListener(Event.ENTER_FRAME, functionProperly); ~

Profile