Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Sep 2007
    Posts
    49
    Thanks
    0
    Thanked 0 Times in 0 Posts

    HELP: conditions aren't working

    Code:
    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?

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    This part is incorrect
    Code:
    if (ladybugMagnet_mc.x < 250);
    		(ladybugMagnet_mc.y < 150); {
    It should be
    Code:
    if (ladybugMagnet_mc.x < 250 && ladybugMagnet_mc.y < 150) {
    The semi colon was terminating the if statement causing it not to work.
    Last edited by _Aerospace_Eng_; 02-11-2008 at 05:35 AM.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    New Coder
    Join Date
    Sep 2007
    Posts
    49
    Thanks
    0
    Thanked 0 Times in 0 Posts
    makes sense though now when I run it, it says

    "Syntax error: else is unexpected." now what is wrong??

    Code:
    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);

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    The semi-colon before the { in the if statement.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #5
    New Coder
    Join Date
    Sep 2007
    Posts
    49
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm not sure which semi-colon you are referring to

  • #6
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Code:
    if (ladybugMagnet_mc.x < 250 && ladybugMagnet_mc.y < 150); {
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #7
    New Coder
    Join Date
    Sep 2007
    Posts
    49
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I did get rid of that semi-colon actually though I now get the message:

    "Cannot assign a non-reference value"

  • #8
    New Coder
    Join Date
    Sep 2007
    Posts
    49
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    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!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •