Cannot make a line through TouchEvent
I know make a line could be create in MouseEvent and Event. But, those of them has a weakness such as Multitouch is not supported in AIR mobile. Then, I migrate those code to TouchEvent. But, It's make me frustated
because these problem always block me out.
Output:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Untitled_fla::MainTimeline/this_move()[Untitled_fla.MainTimeline::frame1:32]
at runtime::ContentPlayer/simulationSendTouchEvent()
at runtime::SimulatedContentPlayer/clientSocketDataHandler()
at runtime::ContentPlayer/simulationSendTouchEvent()
at runtime::SimulatedContentPlayer/clientSocketDataHandler()
Here's the code:
import flash.display.MovieClip;
import flash.display.Graphics;
import flash.events.TouchEvent;
import flash.geom.ColorTransform;
import flash.events.Event;
var lastX:Number
var lastY:Number
var drawing:Boolean = false
Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT
stage.addEventListener(TouchEvent.TOUCH_BEGIN, this_down)
stage.addEventListener(TouchEvent.TOUCH_MOVE, this_move)
stage.addEventListener(TouchEvent.TOUCH_END, touch_up)
function this_down(e:TouchEvent)
{
lastX = e.localX
lastY = e.localY
drawing = true
}
function this_move(e:TouchEvent)
{
if(drawing)
{
this.graphic.lineStyle(20,0x000000)
this.drawArea.graphic.moveTo(lastX,lastY)
this.drawArea.graphic.lineTo(e.localX,e.localY)
lastX = e.localX
lastY = e.localY
e.updateAfterEvent()
}
}
function touch_up(event:TouchEvent)
{
drawing = false
}
