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! =)