Skip to main content
nuurx23171713
Participating Frequently
December 3, 2016
Question

Object appears wrong frame

  • December 3, 2016
  • 1 reply
  • 454 views

Hello, I'm making simple drag and drop game for several letters. Some of the letters appear in the wrong frame and generate an error when clicked.

I'm attaching an example of the file i'm working on, if someone can help would be great (Test2.fla - Google Drive ). A, B, C are fine but XYZ carry on to the  next frame. what can be done to stop this.

stop();

var orig1X:Number=A1.x;

var orig1Y:Number=A1.y;

A1.addEventListener(MouseEvent.MOUSE_DOWN, dragTheObject);

A1.addEventListener (MouseEvent.MOUSE_UP, item1Release);

function dragTheObject(event:MouseEvent):void {

var item:MovieClip=MovieClip(event.target);

item.startDrag();

var topPos:uint=this.numChildren-1;

this.setChildIndex(item, topPos);

}

function item1Release(event:MouseEvent):void {

     var item:MovieClip=MovieClip(event.target);

     item.stopDrag();

       if (pos1.hitTestPoint(item.x,item.y)) {

       item.x=pos1.x;

       item.y=pos1.y;

   

 

  } else {

   

    item.x=orig1X;

       item.y=orig1Y;

   

  } 

};

A1.buttonMode = true;

So this is the code im using for the drag and drop game

This topic has been closed for replies.

1 reply

robdillon
Participating Frequently
December 3, 2016

Look at your timeline. In the first three frames your letters layer is under the box layer. In the next three frames those box frames are empty. This allows the letters to show up. The reason that the letters are showing in frames where you haven't put them is because you have positioned those letters with actionscript. Once an object is controlled by actionscript it will persist on the stage until it is removed by actionscript.

nuurx23171713
Participating Frequently
December 3, 2016

hello rob, thanks for the reply, and how do you remove them with action script?

i've tried to use the following command

    if (contains(A1))

{

        removeChild(A1);

}

works fine  but once I hit the back button to go back, then the code is broken

anyway to solve this problem?

robdillon
Participating Frequently
December 4, 2016

That's where the messy part begins. The simplest, at least to me, solution is to place and remove each of the letters using actionscript. Doing that means that you will only need one frame.

Depending on what your goal is for this project, you could make the movieclip that is dragged one object and then add the letter movieClip to that dragged clip. Then change the letter on every successful drag.