View Full Version : HELP: conditions aren't working
emerald511
02-11-2008, 05:22 AM
function flyAway(event:MouseEvent):void{
if (ladybugMagnet_mc.x < 250);
(ladybugMagnet_mc.y < 150); {
ladyBug_mc.x+=7;
ladyBug_mc.y-=7;}
else {
ladyBug_mc.x+=0;
ladyBug_mc.y+=0;}
}
play_mc.addEventListener(MouseEvent.CLICK, flyAway);
My code works however, even if the ladybugMagnet_mc is not in the place I have stated, the ladyBug_mc still moves. How can I fix that? Also is there a way to keep the bug moving until its off the screen rather than constantly clicking?
_Aerospace_Eng_
02-11-2008, 05:27 AM
This part is incorrect
if (ladybugMagnet_mc.x < 250);
(ladybugMagnet_mc.y < 150); {
It should be
if (ladybugMagnet_mc.x < 250 && ladybugMagnet_mc.y < 150) {
The semi colon was terminating the if statement causing it not to work.
emerald511
02-11-2008, 05:35 AM
makes sense though now when I run it, it says
"Syntax error: else is unexpected." now what is wrong??
function flyAway(event:MouseEvent):void{
if (ladybugMagnet_mc.x < 250 && ladybugMagnet_mc.y < 150); {
ladyBug_mc.x+=7;
ladyBug_mc.y-=7;}
else {
ladyBug_mc.x+=0 && ladyBug_mc.y+=0;}
}
play_mc.addEventListener(MouseEvent.CLICK, flyAway);
_Aerospace_Eng_
02-11-2008, 05:45 AM
The semi-colon before the { in the if statement.
emerald511
02-11-2008, 05:48 AM
I'm not sure which semi-colon you are referring to
_Aerospace_Eng_
02-11-2008, 05:50 AM
if (ladybugMagnet_mc.x < 250 && ladybugMagnet_mc.y < 150); {
emerald511
02-11-2008, 06:10 AM
I did get rid of that semi-colon actually though I now get the message:
"Cannot assign a non-reference value"
emerald511
02-11-2008, 06:20 AM
function flyAway(event:MouseEvent):void{
if (ladybugMagnet_mc.x < 250 && ladybugMagnet_mc.y < 150) {
ladyBug_mc.x+=7;
ladyBug_mc.y-=7;}
else {
ladyBug_mc.x+=0 && ladyBug_mc.y+=0;}
}
play_mc.addEventListener(MouseEvent.CLICK, flyAway);
The last line is supposedly the problem!
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.