# Need help getting buttons to load correctly

**URL:** <https://forum.kirupa.com/t/need-help-getting-buttons-to-load-correctly/258178>\
**Category:** flash\
**Created:** [April 21, 2008, 6:15pm UTC](https://forum.kirupa.com/t/need-help-getting-buttons-to-load-correctly/258178 "2008-04-21T18:15:30Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![akittymom](https://avatars.discourse-cdn.com/v4/letter/a/8baadc/32.png) [@akittymom](https://forum.kirupa.com/u/akittymom)\
**Post date:** [April 21, 2008, 6:15pm UTC](https://forum.kirupa.com/t/need-help-getting-buttons-to-load-correctly/258178/1 "2008-04-21T18:15:30Z")

</div>

I’m working on a game to help kids make good food choices for meals and have created food buttons that, when clicked, move themselves to a plate and put a score into a score box. When clicked again, the food item is removed from the plate and the score is subtracted from the score box. The problem I have now is in adding a second food choice. It does not move itself to the plate and load a score into the score box. It is somehow triggering the other food. Can someone please help me get the food choices to work independetnly? I will be adding about 26 additional food items and need a way to make each work. The score values will vary depending on what the food is and there will be an “OVER LIMIT” popup message if the score goes over 100. Here is the coding I have so far:

package  
{  
//import any class being used by this package  
import flash.display.MovieClip;  
import flash.text.TextField;  
import flash.text.TextFormat;  
import flash.events.MouseEvent;  
public class MealGame extends MovieClip  
{

//altered version  
var offPlate:Boolean; //variable for food off the plate  
var gameScore:int = 0;

public function MealGame()  
{  
//Create a score field for the pancakes.  
var gameScoreField:TextField = new TextField();  
// set the position values  
gameScoreField.x = 445;  
gameScoreField.y = 530;  
//Show the score field  
addChild(gameScoreField);  
var tf:TextFormat = new TextFormat();  
var scoreBox:Object = getChildAt(numChildren-1);  
[//scoreBox.x](https://scoreBox.x) = 445;  
[//scoreBox.y](https://scoreBox.y) = 530;

//Create a new instance of the meal class.  
var pancakes1:Pancakes = new Pancakes();  
var berries1:Berries = new Berries();  
//Display the food on this stage.  
this.addChild(pancakes1);  
this.addChild(berries1);

//Position the food item.  
pancakes1.x = 11;  
pancakes1.y = 42;  
berries1.x = 211;  
berries1.y = 396;  
offPlate = true;

//make the food item a button  
pancakes1.buttonMode = true;  
pancakes1.addEventListener(MouseEvent.CLICK, onClick);  
berries1.buttonMode = true;  
berries1.addEventListener(MouseEvent.CLICK, onClick);

//toggle the food item to put on plate or off the plate  
//toggle adding to the score or removing from the score  
function onClick(event:MouseEvent):void  
{  
if(offPlate)  
{  
pancakes1.x = 119;  
pancakes1.y = 380;  
berries1.x = 515;  
berries1.y = 55;  
//add to score  
gameScore = gameScore + 50;  
gameScoreField.text = " " + String(gameScore);  
tf.font = “Arial”;  
tf.bold = true;  
tf.color = 0x000000;  
tf.size = 32;

```
 //Take this text formatting object; apply it to the textfield
 gameScoreField.setTextFormat(tf);
 
 //toggle the offPlate value
 offPlate = !offPlate;
}
else
{
 pancakes1.x = 11;
 pancakes1.y = 42;
 //berries1.x = 211;
 //berries1.y = 396;
 //remove from score
 gameScore = gameScore - 50;
 gameScoreField.text = " " + String(gameScore);
 tf.font = "Arial";
 tf.bold = true;
 tf.color = 0x000000;
 tf.size = 32;
 //tf.x = 426;

 //Take this text formatting object; apply it to the textfield
 gameScoreField.setTextFormat(tf);
 offPlate = !offPlate;
}

```

}  
}  
}  
}
