Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 05-08-2012, 03:03 AM   #1
connorwilliams1
Registered User
 
Join Date: Mar 2012
Posts: 4
Default [AS3] Multiple problems with my target game

Right now I'm working on a project for my flash class. I'm doing a game where you have 3 baseballs, each named ball1_mc, ball2_mc, or ball3_mc. I am getting an error starting on line 79 saying "1084: Syntax error: expecting identifier before logicaland". I can't figure this out. Also, when I ran the game before getting this error, I couldn't get the ball to stay in its home until clicked or drop when the mouse is released, completely breaking the game. Here is my code so far:

ActionScript Code:
import flash.events.MouseEvent; import flash.events.Event; var startThrow1:Boolean = false; var startThrow2:Boolean = false; var startThrow3:Boolean = false; var holdBall1:Boolean = false; var holdBall2:Boolean = false; var holdBall3:Boolean = false; var rand:Number = 1; var score:Number = 0; Object(this).ball1_mc.buttonMode = true; Object(this).ball2_mc.buttonMode = true; Object(this).ball3_mc.buttonMode = true; Object(this).ball1_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupBall1); Object(this).ball2_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupBall2); Object(this).ball3_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupBall3); Object(this).ball1_mc.addEventListener(MouseEvent.MOUSE_UP, throwBall1); Object(this).ball2_mc.addEventListener(MouseEvent.MOUSE_UP, throwBall2); Object(this).ball3_mc.addEventListener(MouseEvent.MOUSE_UP, throwBall3); function pickupBall1(myEvent:MouseEvent):void {     holdBall1 = true;     startThrow1 = true;     var rand = (Math.floor(Math.random()*3 + 0)); } function pickupBall2(myEvent:MouseEvent):void {     holdBall2 = true;     startThrow2 = true;     var rand = (Math.floor(Math.random()*3 + 0)); } function pickupBall3(myEvent:MouseEvent):void {     holdBall3 = true;     startThrow3 = true;     var rand = (Math.floor(Math.random()*3 + 0)); } function throwBall1(myEvent:MouseEvent):void {     holdBall1 = false; } function throwBall2(myEvent:MouseEvent):void {     holdBall2 = false; } function throwBall3(myEvent:MouseEvent):void {     holdBall3 = false; } stage.addEventListener(Event.ENTER_FRAME, carryBallAround); function carryBallAround (myEvent:Event):void {     if (holdBall1 == true)     {         Object(this).ball1_mc.x = mouseX;         Object(this).ball1_mc.y = mouseY;     }     else if (startThrow1 == true)     {         if(Object(this).ball1_mc.y<280)         {             Object(this).ball1_mc.y +=5;             Object(this).ball1_mc.x +=rand;         }         else         {             if(this.hoop5_mc.hitTestObject(Object(this).ball1_mc)) && hit = false;             {                 hit = true;                 score += 5;                 Object(this).score_txt.text = score;             }             if(this.hoop10_mc.hitTestObject(Object(this).ball1_mc)) && hit = false;             {                 hit = true;                 score += 10;                 Object(this).score_txt.text = score;             }             if(this.hoop25_mc.hitTestObject(Object(this).ball1_mc)) && hit = false;             {                 hit = true;                 score += 25;                 Object(this).score_txt.text = score;             }         }     }         if (holdBall2 == true)     {         Object(this).ball2_mc.x = mouseX;         Object(this).ball2_mc.y = mouseY;     }     else if (startThrow2 == true)     {         if(Object(this).ball2_mc.y<280)         {             Object(this).ball2_mc.y +=5;             Object(this).ball2_mc.x +=rand;         }         else         {             if(this.hoop5_mc.hitTestObject(Object(this).ball2_mc)) && hit = false;             {                 hit = true;                 score += 5;                 Object(this).score_txt.text = score;             }             if(this.hoop10_mc.hitTestObject(Object(this).ball2_mc)) && hit = false;             {                 hit = true;                 score += 10;                 Object(this).score_txt.text = score;             }             if(this.hoop25_mc.hitTestObject(Object(this).ball2_mc)) && hit = false;             {                 hit = true;                 score += 25;                 Object(this).score_txt.text = score;             }     }         if (holdBall3 = true)     {         Object(this).ball3_mc.x = mouseX;         Object(this).ball3_mc.y = mouseY;     }     else if (startThrow3 == true)     {         if(Object(this).ball3_mc.y<280)         {             Object(this).ball3_mc.y +=5;             Object(this).ball3_mc.x +=rand;         }         else         {             if(this.hoop5_mc.hitTestObject(Object(this).ball3_mc)) && hit = false;             {                 hit = true;                 score += 5;                 Object(this).score_txt.text = score;             }             if(this.hoop10_mc.hitTestObject(Object(this).ball3_mc)) && hit = false;             {                 hit = true;                 score += 10;                 Object(this).score_txt.text = score;             }             if(this.hoop25_mc.hitTestObject(Object(this).ball3_mc)) && hit = false;             {                 hit = true;                 score += 25;                 Object(this).score_txt.text = score;             }     } }
connorwilliams1 is offline   Reply With Quote
Old 05-08-2012, 06:43 AM   #2
northmantif
dont Re Member
 
Join Date: May 2009
Location: Poland
Posts: 739
Default

if statements should be something like that:
ActionScript Code:
if(this.hoop10_mc.hitTestObject(Object(this).ball3_mc)) && hit == false)
or
ActionScript Code:
if(this.hoop10_mc.hitTestObject(Object(this).ball3_mc)) && !hit)
is enough.
northmantif is offline   Reply With Quote
Old 05-09-2012, 02:03 AM   #3
connorwilliams1
Registered User
 
Join Date: Mar 2012
Posts: 4
Default

Quote:
Originally Posted by northmantif View Post
if statements should be something like that:
ActionScript Code:
if(this.hoop10_mc.hitTestObject(Object(this).ball3_mc)) && hit == false)
or
ActionScript Code:
if(this.hoop10_mc.hitTestObject(Object(this).ball3_mc)) && !hit)
is enough.
Correct me if I'm wrong, but wouldn't that be an incorrect number of parenthesis? There are 3 left parenthesis and 4 right. Anyways, I got rid of that error, but now an error on line 81: 1050: Cannot assign to a non-reference value.

ActionScript Code:
import flash.events.MouseEvent; import flash.events.Event; var startThrow1:Boolean = false; var startThrow2:Boolean = false; var startThrow3:Boolean = false; var holdBall1:Boolean = false; var holdBall2:Boolean = false; var holdBall3:Boolean = false; var rand:Number = 1; var score:Number = 0; var hit:Boolean = false; Object(this).ball1_mc.buttonMode = true; Object(this).ball2_mc.buttonMode = true; Object(this).ball3_mc.buttonMode = true; Object(this).ball1_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupBall1); Object(this).ball2_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupBall2); Object(this).ball3_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickupBall3); Object(this).ball1_mc.addEventListener(MouseEvent.MOUSE_UP, throwBall1); Object(this).ball2_mc.addEventListener(MouseEvent.MOUSE_UP, throwBall2); Object(this).ball3_mc.addEventListener(MouseEvent.MOUSE_UP, throwBall3); function pickupBall1(myEvent:MouseEvent):void {     holdBall1 = true;     startThrow1 = true;     var rand = (Math.floor(Math.random()*3 + 0)); } function pickupBall2(myEvent:MouseEvent):void {     holdBall2 = true;     startThrow2 = true;     var rand = (Math.floor(Math.random()*3 + 0)); } function pickupBall3(myEvent:MouseEvent):void {     holdBall3 = true;     startThrow3 = true;     var rand = (Math.floor(Math.random()*3 + 0)); } function throwBall1(myEvent:MouseEvent):void {     holdBall1 = false; } function throwBall2(myEvent:MouseEvent):void {     holdBall2 = false; } function throwBall3(myEvent:MouseEvent):void {     holdBall3 = false; } stage.addEventListener(Event.ENTER_FRAME, carryBallAround); function carryBallAround (myEvent:Event):void {     if (holdBall1 == true)     {         Object(this).ball1_mc.x = mouseX;         Object(this).ball1_mc.y = mouseY;     }     else if (startThrow1 == true)     {         if(Object(this).ball1_mc.y<280)         {             Object(this).ball1_mc.y +=5;             Object(this).ball1_mc.x +=rand;         }         else         {             if(this.hoop5_mc.hitTestObject(Object(this).ball1_mc) && hit = false);             {                 hit = true;                 score += 5;                 Object(this).score_txt.text = score;             }             if((this.hoop10_mc.hitTestObject(Object(this).ball1_mc)) && hit == false);             {                 hit = true;                 score += 10;                 Object(this).score_txt.text = score;             }             if((this.hoop25_mc.hitTestObject(Object(this).ball1_mc)) && hit == false);             {                 hit = true;                 score += 25;                 Object(this).score_txt.text = score;             }         }     }         if (holdBall2 == true)     {         Object(this).ball2_mc.x = mouseX;         Object(this).ball2_mc.y = mouseY;     }     else if (startThrow2 == true)     {         if(Object(this).ball2_mc.y<280)         {             Object(this).ball2_mc.y +=5;             Object(this).ball2_mc.x +=rand;         }         else         {             if((this.hoop5_mc.hitTestObject(Object(this).ball2_mc)) && hit == false);             {                 hit = true;                 score += 5;                 Object(this).score_txt.text = score;             }             if((this.hoop10_mc.hitTestObject(Object(this).ball2_mc)) && hit == false);             {                 hit = true;                 score += 10;                 Object(this).score_txt.text = score;             }             if((this.hoop25_mc.hitTestObject(Object(this).ball2_mc)) && hit == false);             {                 hit = true;                 score += 25;                 Object(this).score_txt.text = score;             }         }     }         if (holdBall3 = true)     {         Object(this).ball3_mc.x = mouseX;         Object(this).ball3_mc.y = mouseY;     }     else if (startThrow3 == true)     {         if(Object(this).ball3_mc.y<280)         {             Object(this).ball3_mc.y +=5;             Object(this).ball3_mc.x +=rand;         }         else         {             if((this.hoop5_mc.hitTestObject(Object(this).ball3_mc)) && hit == false);             {                 hit = true;                 score += 5;                 Object(this).score_txt.text = score;             }             if((this.hoop10_mc.hitTestObject(Object(this).ball3_mc)) && hit == false);             {                 hit = true;                 score += 10;                 Object(this).score_txt.text = score;             }             if((this.hoop25_mc.hitTestObject(Object(this).ball3_mc)) && hit == false);             {                 hit = true;                 score += 25;                 Object(this).score_txt.text = score;             }         }     } }
connorwilliams1 is offline   Reply With Quote
Old 05-10-2012, 12:51 AM   #4
tango88
FlashByNight.com
 
tango88's Avatar
 
Join Date: Aug 2006
Posts: 289
Default

Code:
Object(this).score_txt.text = score;
Score is a number. Before you can display it in a text field, you need to convert it to a String:

Code:
Object(this).score_txt.text = String(score);
__________________
Games and more:
Flashbynight.com | Tutes | Twitter
tango88 is offline   Reply With Quote
Old 05-10-2012, 03:40 PM   #5
rrh
throw a trace() in there
 
Join Date: Dec 2006
Posts: 1,982
Default

Not an error, but what is with all the "Object(this)" ? It seems redundant. Just do "this" or even skip it altogether, the "this" is implied.

More on-topic: Which line is line 81?

Also, I think you're not supposed to use semi-colons on your if conditions, I think someone else here did it and was wondering why their things were executing even when their condition should be false:
Code:
//BAD
if (something);
 {
   //this always executes, no matter the value of "something"
 }

//GOOD
if (something)
 {
   //this only executes, is "something" is true
 }

Last edited by rrh; 05-10-2012 at 03:45 PM.
rrh is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 07:41 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.