Вопрос

I'm really new to using Action Script in general and could use a good explanation on how to do this as well as how it works.

I'm trying to create a stage event in AS3 for Android.

When the user touches the stage and not an object in particular I need to detect if they are dragging and the location of where there finger has dragged to.

I've started like this to detect if they have touched the stage:

stage.addEventListener(TouchEvent.TOUCH_BEGIN, stageTouchBegin); 

var stageTouchDragBounds:Rectangle = new Rectangle(0, 0, stage.stageWidth, stage.stageHeight);

function stageTouchBegin(event:TouchEvent):void
{
event.target.startTouchDrag(event.touchPointID, false, stageTouchDragBounds:Rectangle);
trace(event.stageX);
trace(event.stageY);
}

This line is where I get the error and I'm assuming that it's because target would typically be referencing a movie symbol or something but in this case it's not because its the stage. I tried replacing target with stage but it didn't work:

event.target.startTouchDrag(event.touchPointID, false, stageTouchDragBounds:Rectangle);

Here is the error: 1061: Call to a possibly undefined method startTouchDrag through a reference with static type flash.events:TouchEvent.


From there my plan was to proceed to use something like this to start recording where they were at:

var curPosX; var curPosY;

function stageTouchMoveHandler(event:TouchEvent):void
{   
trace(event.stageX);
this.curPosX = event.stageX;
trace(event.stageY);
this.curPosY = event.stageY;
}

Then handle the ending as such:

function stageTouchEndHandler(event:TouchEvent):void
{
event.target.stopTouchDrag(event.touchPointID);
}

Any insight/advice on how to do this or an explanation of target, especially example code, would be greatly appreciated. Thank you for your time!

Это было полезно?

Решение

After thinking about what you are trying to do, I think the answer to your question is don't call the startTouchDrag() method and proceed w/your plans. What you have shown is the right approach to determine where the user started/stopped their "touch move" gesture.

It makes no sense to try and drag the stage ... the stage is literally a stage that your Flash movie is shown on. It contains the entire Flash application, and as such cannot be dragged.

To reiterate what I stated in my comment above, startTouchDrag() is a method you call on a Sprite (or some object that extends Sprite). This method is meant to be used when you want to drag something across the screen, like in a drag and drop operation.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top