Make an object disappear when the player touches the touch screen twice

advertisements

I'm trying to make a flash game for a touch screen (android). My player can take some items and put them in his inventory. The player can, then, click on a item in his inventory and drag it where he wants on the scene. But, I'd like to make the item disapear of the screen when the player double tap on the screen. For the moment, my player need just to taps one. (and it's frustrating as, if he hasn't put the item into the correct space and wants to corrects it by dragging the item again, it's disappearing since he clicks on a wrong space).

I know that I have to change my "removeDraggedItem" function, but I can't figure it out how to tell it that I want this function only if the player ahs double tap on the screen (not just one click)

Here's my code. If someone has an idea....

public function itemClick(e:Event):void{
            inv.draggingItem = false;
            var nameofMC:String;
            var tempMC;
            var draggedName:String = draggedItem.displayName;
            if (draggedItem.lookTag)
                draggedName = draggedName + draggedItem.lookTag;
            if (newFriend){
                nameofMC = "action_"+draggedName+"_"+newFriend.displayName;
                //trace ("Looking for "+nameofMC);
                try {
                    tempMC = getDefinitionByName(nameofMC);
                    //trace ("MC found.");
                    removeDraggedItem();
                    if (speech)
                        speech.dispatchEvent(new Event("stopTalking"));
                    tempMC = new tempMC;
                    playerAction = new PlayerAction(stageRef, draggedItem, newFriend, tempMC, false);
                }
                catch(e){
                    //trace ("No MC found.  Checking for dialog option...");
                    try {
                        var tempData = linesData.dialog[newFriend.displayName].useObject[draggedItem.displayName];
                        if (tempData != "" && tempData != null){
                            //trace ("Dialog option found.");
                            removeDraggedItem();
                            alignPlayer();
                            if (speech)
                                speech.dispatchEvent(new Event("stopTalking"));
                            dialog = new Dialog(stageRef, newFriend, draggedItem, false);
                        }
                    }
                    catch(e){
                        //trace ("No dialog option found.  Defaulting to player line.");
                        alignPlayer();
                        if (speech)
                            speech.dispatchEvent(new Event("stopTalking"));
                        var actionName:String = "Use_"+newFriend.displayName;
                        if (newFriend.lookTag)
                            actionName = actionName+newFriend.lookTag;
                        speech = new Speech(stageRef, draggedItem, actionName);
                    }

                }
            } else {
                removeDraggedItem();
            }

        }

private function removeDraggedItem():void{
            stageRef.removeEventListener(MouseEvent.MOUSE_MOVE, dragItem);
            stageRef.removeEventListener(Event.ENTER_FRAME, itemHitTest);
            draggedItem.removeEventListener(MouseEvent.CLICK, itemClick);

            stageRef.removeChild(draggedItem);
            toolbar.useText.text = "";

            if (stageRef.contains(this))
                stageRef.removeChild(this);

            Mouse.show();
            Engine.playerControl = true;
        }


On the first tap set a variable (eg screenTap) to true and set up a Timer for the maximum amount of milliseconds you will allow between taps in a double-tap. When the Timer expires reset screenTap to false.
Then, in your tap screen handler, check if screenTap is true. If so, remove the item.