# 1061: Call to a possibly undefined method startDrag through a reference with

**URL:** <https://forum.kirupa.com/t/1061-call-to-a-possibly-undefined-method-startdrag-through-a-reference-with/327947>\
**Category:** Uncategorized\
**Created:** [April 7, 2012, 9:55pm UTC](https://forum.kirupa.com/t/1061-call-to-a-possibly-undefined-method-startdrag-through-a-reference-with/327947 "2012-04-07T21:55:22Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Profitemole](https://avatars.discourse-cdn.com/v4/letter/p/f08c70/32.png) [@Profitemole](https://forum.kirupa.com/u/Profitemole)\
**Post date:** [April 7, 2012, 9:55pm UTC](https://forum.kirupa.com/t/1061-call-to-a-possibly-undefined-method-startdrag-through-a-reference-with/327947/1 "2012-04-07T21:55:22Z")

</div>

I’ve got a piece of code that means a button will only become clickable if a set of keys are dragged to a certain location.

This is my code for that:

Keys.buttonMode = true;

Keys.addEventListener(MouseEvent.MOUSE\_DOWN, drag1);  
Keys.addEventListener(MouseEvent.MOUSE\_UP, drop1);

function drag1(event) {  
Keys.startDrag(true);  
}

function drop1(event) {  
if (Keys.hitTestObject(Key\_box)==true) {  
Keys.x=69;  
Keys.y=505;  
Keys.stopDrag();  
AfterKey.addEventListener(MouseEvent.CLICK, goMainRoom);

```
} else {
    Keys.x=102;
    Keys.y=285;
    Keys.stopDrag();
}

```

AfterKey.addEventListener(MouseEvent.CLICK, goMainRoom);  
function goMainRoom(event:MouseEvent):void {  
gotoAndStop(60);  
}

}

Keys is the draggable and AfterKey is the button that can’t be pressed until the keys are at a certain location.

Anyway, I want the same piece of code for some ‘bandages’ and so when I copy the code and replace drag1 and drop1 with drag2 and drop2, I get this error message.  
This is the code I have for this:

Bandage.buttonMode = true;

Bandage.addEventListener(MouseEvent.MOUSE\_DOWN, drag2);  
Bandage.addEventListener(MouseEvent.MOUSE\_UP, drop2);

function drag2(event:MouseEvent):void {  
Bandage.startDrag(true);  
}

function drop2(event) {  
if (Bandage.hitTestObject(Bandage\_box)==true) {  
Bandage.x=69;  
Bandage.y=505;  
Bandage.stopDrag();  
AfterBandage.addEventListener(MouseEvent.CLICK, goHallDown);

} else {  
Bandage.x=102;  
Bandage.y=285;  
Bandage.stopDrag();  
}

AfterBandage.addEventListener(MouseEvent.CLICK, goHallDown);  
function goHallDown(event:MouseEvent):void {  
gotoAndStop(85);  
}

}

I don’t get why it’s not working, I also get:  
1119: Access of possibly undefined property buttonMode through a reference with static type flash.display:SimpleButton.

It’s really bugging me because I can’t see why it’s not working.

Any help would be fantastic!  
Thanks in advance! =)
