actionscript 3 - Starling Touch event throws an unexpected error -
if else having same issue, facing in few of projects never bother finding cause.
every thing works fine while adding listener touchevents:
btn.addeventlistener(touchevent.touch,function(e:touchevent){ var t:touch = e.gettouch(stage); if(t.phase == touchphase.ended) { resetball(); } });
but sometime if somehow mouse hover through object project stops, , throws following error.
typeerror: error #1009: cannot access property or method of null object reference. @ function/game.as$0:anonymous()[...src\game.as:45] @ starling.events::eventdispatcher/invokeevent()[/users/redge/dropbox/development/starling/starling/src/starling/events/eventdispatcher.as:141] @ starling.events::touchevent/dispatch()[/users/redge/dropbox/development/starling/starling/src/starling/events/touchevent.as:174] @ starling.events::touchprocessor/processtouches()[/users/redge/dropbox/development/starling/starling/src/starling/events/touchprocessor.as:186] @ starling.events::touchprocessor/advancetime()[/users/redge/dropbox/development/starling/starling/src/starling/events/touchprocessor.as:135] @ starling.core::starling/advancetime()[/users/redge/dropbox/development/starling/starling/src/starling/core/starling.as:379] @ starling.core::starling/nextframe()[/users/redge/dropbox/development/starling/starling/src/starling/core/starling.as:369] @ starling.core::starling/onenterframe()[/users/redge/dropbox/development/starling/starling/src/starling/core/starling.as:568]
the standard check if touch object returned gettouch()
null
before checking phase
property.
var touch:touch = e.gettouch( stage ); if ( touch ) { if( touch.phase == touchphase.ended ) { resetball(); } }
from starling wiki:
private function ontouch(event:touchevent):void { var touch:touch = event.gettouch(this, touchphase.began); if (touch) { var localpos:point = touch.getlocation(this); trace("touched object @ position: " + localpos); } }
Comments
Post a Comment