Hello everyone,
I am having been building a drag n drop flash game where you need to drag pictures of organisms into their position on a food web. The code was working when it was a simple food chain with each animals only have one position on the chain. I have no decided to make it a more complex and have things such as plants, having a couple of different positions in the chain. I have decided to try this using an array for each of the sets of pictures. At the moment the pictures can be picked up and moved around the screen, but not placed on any of the targets that I have put on the screen. My other problem is that the following error keeps coming up whenever I go to the frame.
TypeError: Error #1010: A term is undefined and has no properties.
at foodweb_fla::MainTimeline/activateDraggables()
at foodweb_fla::MainTimeline/frame6()
I have been trying for a couple of days now to work out whats going on withoutmuch luck due to my very average flash skills. The coding that I have done so far is below:
stop();
var startX2:Number;
var startY2:Number;
var counter2:Number=0;
score_txt.text=score;
var dropTargetss = new Array();
dropTargetss[0]=targetsun2_mc1;
dropTargetss[1]=targetsun2_mc2;
dropTargetss[2]=targetsun2_mc3;
dropTargetss[3]=targetsun2_mc4;
var dropTargetsp = new Array();
dropTargetsp[0]=targetplant2_mc1;
dropTargetsp[1]=targetplant2_mc2;
dropTargetsp[2]=targetplant2_mc3;
var dropTargetsi = new Array();
dropTargetsi[0]=targetinsect2_mc1;
dropTargetsi[1]=targetinsect2_mc2;
var draggableObjectss = new Array();
draggableObjectss[0]=sun2_mc1;
draggableObjectss[1]=sun2_mc2;
draggableObjectss[2]=sun2_mc3;
draggableObjectss[3]=sun2_mc4;
var draggableObjectsp = new Array();
draggableObjectsp[0]=plant2_mc1;
draggableObjectsp[1]=plant2_mc2;
draggableObjectsp[2]=plant2_mc3;
var draggableObjectsi = new Array();
draggableObjectsi[0]=insect2_mc1;
draggableObjectsi[1]=insect2_mc2;
Next3_b.addEventListener(MouseEvent.CLICK, onGuessClick3);
SA3_b.addEventListener(MouseEvent.CLICK, onSAClick3);
bird2_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickUp5);
snake2_mc.addEventListener(MouseEvent.MOUSE_UP, dropIt5);
bird2_mc.buttonMode=true;
snake2_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickUp5);
bird2_mc.addEventListener(MouseEvent.MOUSE_UP, dropIt5);
snake2_mc.buttonMode=true;
//BUTTON FUNCTIONS
function onGuessClick3(event:MouseEvent) {
//if(counter2 == 11){
gotoAndPlay(7);
//} else {
//reply2_txt.text = "You need to complete this food chain before moving forward!";
//}
}
function onSAClick3(event:MouseEvent) {
gotoAndStop(1);
}
//PICKUP AND DROP FUNCTIONS
function activateDraggables():void {
for (var i:int = 0; i < draggableObjectss.length; i++) {
draggableObjectss*.buttonMode=true;
draggableObjectss*.addEventListener(MouseEvent.MOUSE_DOWN, pickUp2);
}
for (var j:int = 0; j < draggableObjectsp.length; j++) {
draggableObjectsp[j].buttonMode=true;
draggableObjectsp[j].addEventListener(MouseEvent.MOUSE_DOWN, pickUp3);
}
for (var k:int = 0; k < draggableObjectss.length; k++) {
draggableObjectsi[k].buttonMode=true;
draggableObjectsi[k].addEventListener(MouseEvent.MOUSE_DOWN, pickUp4);
}
}
activateDraggables();
function pickUp2(event:MouseEvent):void {
// add listener to stage to prevent stickiness
stage.addEventListener(MouseEvent.MOUSE_UP, dropIt2);
event.target.startDrag();
reply2_txt.text="Now put the tile in the correct position of the food chain.";
startX=event.target.x;
startY=event.target.y;
}
function dropIt2(event:MouseEvent):void {
event.target.stopDrag();
stage.removeEventListener(MouseEvent.MOUSE_UP, dropIt2);
if (event.target.dropTarget&&dropTargetss.indexOf(event.target.dropTarget)>-1) {
reply2_txt.text="Good Job";
event.target.x=event.target.dropTarget.x;
event.target.removeEventListener(MouseEvent.MOUSE_DOWN, pickUp2);
event.target.buttonMode=false;
} else {
reply2_txt.text="Try Again!";
event.target.x=startX;
event.target.y=startY;
}
}
function pickUp3(event:MouseEvent):void {
// add listener to stage to prevent stickiness
stage.addEventListener(MouseEvent.MOUSE_UP, dropIt3);
event.target.startDrag();
reply2_txt.text="Now put the tile in the correct position of the food chain.";
startX=event.target.x;
startY=event.target.y;
}
function dropIt3(event:MouseEvent):void {
event.target.stopDrag();
stage.removeEventListener(MouseEvent.MOUSE_UP, dropIt3);
if (event.target.dropTarget&&dropTargetsp.indexOf(event.target.dropTarget)>-1) {
reply2_txt.text="Good Job";
event.target.x=event.target.dropTarget.x;
event.target.removeEventListener(MouseEvent.MOUSE_DOWN, pickUp2);
event.target.buttonMode=false;
} else {
reply2_txt.text="Try Again!";
event.target.x=startX;
event.target.y=startY;
}
}
function pickUp4(event:MouseEvent):void {
// add listener to stage to prevent stickiness
stage.addEventListener(MouseEvent.MOUSE_UP, dropIt4);
event.target.startDrag();
reply2_txt.text="Now put the tile in the correct position of the food chain.";
startX=event.target.x;
startY=event.target.y;
}
function dropIt4(event:MouseEvent):void {
event.target.stopDrag();
stage.removeEventListener(MouseEvent.MOUSE_UP, dropIt4);
if (event.target.dropTarget&&dropTargetsi.indexOf(event.target.dropTarget)>-1) {
reply2_txt.text="Good Job";
event.target.x=event.target.dropTarget.x;
event.target.removeEventListener(MouseEvent.MOUSE_DOWN, pickUp2);
event.target.buttonMode=false;
} else {
reply2_txt.text="Try Again!";
event.target.x=startX;
event.target.y=startY;
}
}
function pickUp5(event:MouseEvent):void {
event.target.startDrag(true);
reply2_txt.text="Now put the tile in the correct position of the food chain.";
event.target.parent.addChild(event.target);
startX=event.target.x;
startY=event.target.y;
}
function dropIt5(event:MouseEvent):void {
event.target.stopDrag();
var myTargetName:String="target"+event.target.name;
var myTarget:DisplayObject=getChildByName(myTargetName);
if (event.target.dropTarget!=null&&event.target.dropTarget.parent==myTarget) {
reply2_txt.text="Good Work!";
event.target.removeEventListener(MouseEvent.MOUSE_DOWN, pickUp5);
event.target.removeEventListener(MouseEvent.MOUSE_UP, dropIt5);
event.target.buttonMode=false;
event.target.x=myTarget.x;
event.target.y=myTarget.y;
counter2++;
} else {
reply2_txt.text="That tile doesn't go there!";
event.target.x=startX2;
event.target.y=startY2;
}
if (counter2==11) {
reply2_txt.text="Congratulations you have completed the forest ecosystem!";
score++;
score++;
score++;
score++;
score++;
score++;
score_txt.text=score;
}
}
Any help will be much appreciated. Thankyou in advance