first you will need to create a score box simply get out your square tool draw a box then, insert a text box from your text tool convert to symbol be sure to embed the font you plan on using. Name the symbol and the text box within it.
for simplicity I have named my symbol scoreBox and the internal text box digits
now for the code
package { import flash.display.*; import flash.events.*; public class document extends MovieClip { var avatarGuy:avatar; var fallFruit:fallingObjects; var points:Number;
function document():void { points = 0; fallFruit = new fallingObjects(); addChild(fallFruit); avatarGuy = new avatar(); avatarGuy.x = 100; avatarGuy.y = 267; addChild(avatarGuy); var score:scoreBox = new scoreBox(); score.x = 30; score.y = 25; addChild(score); score.digits.text = points.toString(); addEventListener(Event.ENTER_FRAME, loop); function loop(event):void { for(var i:int = 0; i < fallFruit.numChildren;i++) { if(avatarGuy.hitTestObject(fallFruit.getChildAt(i))) { var fruit = fallFruit.getChildAt(i); if(fruit is apple) { scoreSystem(5) } fallFruit.removeChild(fallFruit.getChildAt(i)); } } } function scoreSystem(n):void { points = points+n; score.digits.text = points.toString(); } } } }
How would I set different scores to add to the scores depending on which fruit I hit?
package { import flash.display.MovieClip; import flash.utils.*; import flash.events.TimerEvent; public class FallingObjects extends MovieClip { public var appleArray:Array; public var strawberryArray:Array; public var orangeArray:Array; public var watermelonArray:Array; public var gameTimer:Timer;
public function FallingObjects() { appleArray = new Array(); strawberryArray = new Array(); orangeArray = new Array(); watermelonArray = new Array(); gameTimer = new Timer(25); gameTimer.addEventListener(TimerEvent.TIMER, dropFruit); gameTimer.start(); } private function dropFruit(event:TimerEvent):void { if (Math.random() < 0.009) { var randomXApple:Number = Math.random() * 550; var randomXStrawberry:Number = Math.random() * 550; var randomXOrange:Number = Math.random() * 550; var apples:apple = new apple(); var strawberrys:strawberry = new strawberry(); var orangesrange = new orange(); apples.x = randomXApple; apples.y = -30; strawberrys.x = randomXStrawberry; strawberrys.y = -30; oranges.x = randomXOrange; oranges.y = -30; appleArray.push(apples); addChild(apples); strawberryArray.push(strawberrys); addChild(strawberrys); orangeArray.push(oranges); addChild(oranges); } for each(apples in appleArray) { apples.y += 1.4; } for each(strawberrys in strawberryArray) { strawberrys.y += 2.2; } for each (oranges in orangeArray) { oranges.y++; } if (Math.random() < 0.003) { var randomXWatermelon:Number = Math.random() * 550; var watermelons:watermelon = new watermelon(); watermelons.x = randomXWatermelon; watermelons.y = -30; watermelonArray.push(watermelons); addChild(watermelons); } for each(watermelons in watermelonArray) { watermelons.y += 3.8; } } } }
It came up with this error TypeError: Error #1010: A term is undefined and has no properties. at Document()
I created the box with the square tool. Made a text box and typed 78 into it made it so I could see the text and made only the text box into a symbol with the name of digits. Then I selected the text box and the rectangle together and symbolized it and called it scoreBox. I'm pretty sure I follow your instructions.
public class Document extends MovieClip { var avatarGuy:avatar; var fallFruit:FallingObjects; var points:Number;
public function Document() { trace("Document Class Working" points = 0; var avatarGuy = new avatar(stage); avatarGuy.x = 50; avatarGuy.y = 267; addChild(avatarGuy); var fallFruit = new FallingObjects(); addChild(fallFruit); var score:scoreBox = new scoreBox(); score.x = 250; score.y = 350; addChild(score); score.digits.text = points.toString(); addEventListener(Event.ENTER_FRAME, loop); function loop(event):void { for(var i:int = 0; i < fallFruit.numChildren;i++) { if(avatarGuy.hitTestObject(fallFruit.getChildAt(i))) { var fruit = fallFruit.getChildAt(i); if(fruit is apple) { scoreSystem(5); } fallFruit.removeChild(fallFruit.getChildAt(i)); } } } function scoreSystem(n):void { points = points + n; score.digits.text = points.toString(); } }
I tried to keep on going with the symbol stuff and I typed in 0 in the box and then made called gave it the instance name of digits and than I ran it and as soon as a touched a apple it went blank and when I hit another apple it went back to saying 0.