gotoAndStop when if statement is true problem
Hi guys,
Ive asked a question yesterday with this code but it was a different one. Im stuck now again the whole day and i cannot find any related answered question here about this.
I need to get flash to jump to a certain frame/label when a statement is true. In other words in my program ive made a simple drag and drop game and what i need is that when all are correct my right_mc smiley comes up and when wrong my wrong_mc smiley comes up. But i need flash to gotoAndStop at the last frame of the program if the answers are correct, and if the answers are not correct (else) it should stay on the current site so that the player can try again.
Ive tried many different codes but just jumps directly to the last frame without showing the game so what am i doing wrong? Im thinking i have the right arguments but im kinda confused now after all. Would be very much appriciated forany help. I googled, read in the book etc but can only find regular gotoAndStop actions without any if statements so i cant even find any examples 😕😕
At the very end of the page is the code bit i mean.
right_mc.visible=false;
wrong_mc.visible=false;
var orig1X:Number=item1_mc.x;
var orig1Y:Number=item1_mc.y;
var orig2X:Number=item2_mc.x;
var orig2Y:Number=item2_mc.y;
var orig3X:Number=item3_mc.x;
var orig3Y:Number=item3_mc.y;
var orig4X:Number=item4_mc.x;
var orig4Y:Number=item4_mc.y;
var orig5X:Number=item5_mc.x;
var orig5Y:Number=item5_mc.y;
item1_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragTheObject);
item1_mc.addEventListener(MouseEvent.MOUSE_UP, item1Release);
item2_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragTheObject);
item2_mc.addEventListener(MouseEvent.MOUSE_UP, item2Release);
item3_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragTheObject);
item3_mc.addEventListener(MouseEvent.MOUSE_UP, item3Release);
item4_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragTheObject);
item4_mc.addEventListener(MouseEvent.MOUSE_UP, item4Release);
item5_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragTheObject);
item5_mc.addEventListener(MouseEvent.MOUSE_UP, item5Release);
//skapar en liten hand när man placerar musen över objekten
item1_mc.buttonMode=true;
item2_mc.buttonMode=true;
item3_mc.buttonMode=true;
item4_mc.buttonMode=true;
item5_mc.buttonMode=true;
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 (avc_mc.hitTestPoint(item.x,item.y)) {
item.x=avc_mc.x;
item.y=avc_mc.y;
} else {
item.x=orig1X;
item.y=orig1Y;
}
};
function item2Release(event:MouseEvent):void {
var item:MovieClip=MovieClip(event.target);
item.stopDrag();
if (miljo_mc.hitTestPoint(item.x,item.y)) {
item.x=miljo_mc.x;
item.y=miljo_mc.y;
} else {
item.x=orig2X;
item.y=orig2Y;
}
};
function item3Release(event:MouseEvent):void {
var item:MovieClip=MovieClip(event.target);
item.stopDrag();
if (trashbag_mc.hitTestPoint(item.x,item.y)) {
item.x=trashbag_mc.x;
item.y=trashbag_mc.y;
} else {
item.x=orig3X;
item.y=orig3Y;
}
};
function item4Release(event:MouseEvent):void {
var item:MovieClip=MovieClip(event.target);
item.stopDrag();
if (avs_mc.hitTestPoint(item.x,item.y)) {
item.x=avs_mc.x;
item.y=avs_mc.y;
} else {
item.x=orig4X;
item.y=orig4Y;
}
}; function item5Release(event:MouseEvent):void {
var item:MovieClip=MovieClip(event.target);
item.stopDrag();
if (apotek_mc.hitTestPoint(item.x,item.y)) {
item.x=apotek_mc.x;
item.y=apotek_mc.y;
} else {
item.x=orig5X;
item.y=orig5Y;
}
answer_btn.addEventListener(MouseEvent.CLICK, checkAnswers);
reset_btn.addEventListener(MouseEvent.CLICK, reset);
}; function checkAnswers(event:MouseEvent):void {
if (avc_mc.hitTestPoint(item1_mc.x,item1_mc.y) &&
miljo_mc.hitTestPoint(item2_mc.x,item2_mc.y) &&
trashbag_mc.hitTestPoint(item3_mc.x,item3_mc.y) &&
avs_mc.hitTestPoint(item4_mc.x,item4_mc.y) &&
apotek_mc.hitTestPoint(item5_mc.x,item5_mc.y)) {
wrong_mc.visible = false;
right_mc.visible = true;
} else {
wrong_mc.visible = true;
right_mc.visible = false;
}
};function reset(event:MouseEvent):void {
item1_mc.x=orig1X;
item1_mc.y=orig1Y;
item2_mc.x=orig2X;
item2_mc.y=orig2Y;
item3_mc.x=orig3X;
item3_mc.y=orig3Y;
item4_mc.x=orig4X;
item4_mc.y=orig4Y;
item5_mc.x=orig5X;
item5_mc.y=orig5Y;
right_mc.visible=false;
wrong_mc.visible=false;
}
if (right_mc.visible == true);
gotoAndStop ("theend");
else
{
gotoAndStop ("Game");
}
}
