# Problems with Arrays - 2 arrays seem to be clashing

**URL:** <https://forum.kirupa.com/t/problems-with-arrays-2-arrays-seem-to-be-clashing/325314>\
**Category:** flash\
**Created:** [October 9, 2011, 9:54am UTC](https://forum.kirupa.com/t/problems-with-arrays-2-arrays-seem-to-be-clashing/325314 "2011-10-09T09:54:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![stevie7](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@stevie7](https://forum.kirupa.com/u/stevie7)\
**Post date:** [October 9, 2011, 9:54am UTC](https://forum.kirupa.com/t/problems-with-arrays-2-arrays-seem-to-be-clashing/325314/1 "2011-10-09T09:54:39Z")

</div>

Hi There,

I am new to AS3 and I’m struggling through arrays at the moment…I’m sure it is something simple I am doing wrong but I can’t for the life of me see it…

I am creating a simple swf that allows a kid to design a layout for a game.

On the first scene, they can drag a collection of signs onto the board. They can drag any number of the signs into position and then click to continue. code for this frame is:

// Drag and Drop signs  
//

var dragArray\_Sign:Array = [sign1, sign2, sign3, sign4, sign5, sign6, sign7, sign8];

var currentClip\_Sign:MovieClip;  
var startX\_Sign:Number;  
var startY\_Sign:Number;

for(var s:int = 0; s \< dragArray\_Sign.length; s++) {

```
dragArray_Sign[s].buttonMode = true;

```

dragArray\_Sign[s].addEventListener(MouseEvent.MOUSE\_DOWN, item\_onMouseDown\_Sign);

}

function item\_onMouseDown\_Sign(event:MouseEvent):void {

```
currentClip_Sign = MovieClip(event.currentTarget);

startX_Sign = currentClip_Sign.x;

startY_Sign = currentClip_Sign.y;

addChild(currentClip_Sign); //bring to the front

currentClip_Sign.startDrag();

stage.addEventListener(MouseEvent.MOUSE_UP, stage_onMouseUp_Sign);

```

}

function stage\_onMouseUp\_Sign(event:MouseEvent):void {

```
stage.removeEventListener(MouseEvent.MOUSE_UP, stage_onMouseUp_Sign);

currentClip_Sign.stopDrag();

var index:int = dragArray_Sign.indexOf(currentClip_Sign);

```

}  
// end drag and drop signs  
//

/\* Click to Go to Frame and Play  
\*/

next\_btn.addEventListener(MouseEvent.CLICK, fl\_ClickToGoToAndPlayFromFrame);

function fl\_ClickToGoToAndPlayFromFrame(event:MouseEvent):void  
{  
gotoAndPlay(10);  
}

* * *

On the next scene, I want to remove the ability to drag and drop these signs as they are now part of the board. On this scene we have a selection of 8 cars that can be used as counters to be dragged and dropped around the board as they play the game.

I have tried to create another array for this. The code for this frame is:

stop();

// Remove drag  
//

addEventListener(Event.ENTER\_FRAME, fl\_NoDrop);

function fl\_NoDrop(event:Event):void  
{  
sign1.stopDrag();  
sign1.buttonMode = false;  
sign2.stopDrag();  
sign2.buttonMode = false;  
sign3.stopDrag();  
sign3.buttonMode = false;  
sign4.stopDrag();  
sign4.buttonMode = false;  
sign5.stopDrag();  
sign5.buttonMode = false;  
sign6.stopDrag();  
sign6.buttonMode = false;  
sign7.stopDrag();  
sign7.buttonMode = false;  
sign8.stopDrag();  
sign8.buttonMode = false;

}

/\* Drag and Drop cars  
\*/

var dragArray:Array = [Car1\_mc, Car2\_mc, Car3\_mc, Car4\_mc, Car5\_mc, Car6\_mc, Car7\_mc, Car8\_mc];

var currentClip:MovieClip;  
var startX:Number;  
var startY:Number;

for(var i:int = 0; i \< dragArray.length; i++) {

```
dragArray*.buttonMode = true;

```

dragArray\*.addEventListener(MouseEvent.MOUSE\_DOWN, item\_onMouseDown);

}

function item\_onMouseDown(event:MouseEvent):void {

```
currentClip = MovieClip(event.currentTarget);

startX = currentClip.x;

startY = currentClip.y;

addChild(currentClip); //bring to the front

currentClip.startDrag();

stage.addEventListener(MouseEvent.MOUSE_UP, stage_onMouseUp);

```

}

function stage\_onMouseUp(event:MouseEvent):void {

```
stage.removeEventListener(MouseEvent.MOUSE_UP, stage_onMouseUp);

currentClip.stopDrag();

var index:int = dragArray.indexOf(currentClip);

```

}

* * *

The problem I am having is that unless I move all 8 signs, the signs remain draggable on the next frame.

If I move all 8 signs then on the next frame they are not draggable, however, the cars are not draggable either?!?!

Please help!!

Stephen
