---
title: "Score 10 = VINST"
type: "forum-thread"
url: "https://www.webforum.nu/amne/flash/151572-score-10-vinst"
topic: "Flash"
topic_url: "https://www.webforum.nu/amne/flash"
author: "thejimmo"
published: "2006-09-21T11:05:16.000Z"
updated: "2006-10-11T06:40:16.000Z"
replies: 2
views: 319
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/flash/151572-score-10-vinst"
---

# Score 10 = VINST

## #1 — thejimmo, 2006-09-21T11:05Z

Hej,

Jag har detta actionscriptet i ett "catch"-spel. Vad jag inte kan få rätt på är hur jag ska göra för att skicka spelaren vidare vid vinst. Jag hade tänkt att man ska vinna när man fått 10 poäng (1p= en fångad boll)

Kan någon schysst actionscriptare hjälpa mig?

//this produces random balls that fall from the sky
depth = 0;
allBalls = new Array();
function makeNewClip() {
	clearInterval(ranID);
	ran = (Math.random()\*4000)+1000;
	ranID = setInterval(makeNewClip, ran);
	newClip = \_root.attachMovie('circle', 'circle'+depth, depth++);
	allBalls.push(newClip);
	//trace(allBalls);
	newClip.\_x = Math.random()\*Stage.width;
	newClip.\_y = -50;
	newClip.speed = (Math.random()\*10)+5;
	newClip.onEnterFrame = function() {
		this.\_y += this.speed;
		if (this.\_y\>Stage.height) {
			updateScore(-1);
			for (i=0; i\<allBalls.length; i++) {
				if (this == allBalls*) {
					allBalls.splice(i, 1);
					//trace(allBalls)
				}
			}
			this.removeMovieClip();
		}
	};
}
makeNewClip();
//
\_root.attachMovie('slider', 'slider_mc', -1);
slider_mc.\_y = Stage.height-20;
maxSpeed=20;
xSpeed=0;
watchKeyboard = new Object();
watchKeyboard.onKeyDown = function() {
	clearInterval(easeID);
	if (Key.getCode() == Key.LEFT) {
		if(xSpeed\>-maxSpeed){
			xSpeed--;
			
		}
	}
	if (Key.getCode() == Key.RIGHT) {
		if(xSpeed\<maxSpeed){
			xSpeed++;
			
		}
	}
};
watchKeyboard.onKeyUp=function(){

	clearInterval(easeID);
	easeID=setInterval(ease,20);
}
Key.addListener(watchKeyboard);
slider_mc.onEnterFrame=function(){
	
	this.\_x+=xSpeed;
	
}
function ease(){
	if(xSpeed\>0){
		xSpeed--;
	}
	if(xSpeed\<0){
		xSpeed++;
	}
	if(xSpeed==0){
		clearInterval(easeID);
		
	}
}
//
\_root.createEmptyMovieClip('watchCollision', -2);
watchCollision.onEnterFrame = function() {
	for (i=0; i\<allBalls.length; i++) {
		if (allBalls*.hitTest(slider_mc)) {
			//trace('we hit the slider');
			allBalls*.removeMovieClip();
			allBalls.splice(i, 1);
			updateScore(1);
		}
	}
};
score = 0;
function updateScore(amount) {
	score += amount;
	score_txt.text = 'Fångade: '+score;
}
updateScore(0);

/The jimmo***

Permalänk: https://www.webforum.nu/p/151572

## #2 — Stig, 2006-10-10T21:07Z

Nu är jag inte någon super programerare men jag är logisk i mitt tanke sätt.
Jag skulle göra ett mc med 3 frames som hela tiden loopar och kollar vad
din variable score har för värde i frame 3, (se till att du har hela sökvägen till din variable score från \_root) har den värde 10 så ska den göra något alltså en if sats
har den inte det så loopar den bara vidare till frame 1 osv. Detta mc lägger man seda ut på huvudlinjen så att det alltid finns med.

Permalänk: https://www.webforum.nu/p/1879268

## #3 — mirandir, 2006-10-11T06:40Z

Du har ju en funktion som räknar poängen. Lägg in ett vanligt if-test där för att kolla vad poängen är och när den blir lika med eller större än 10 så skicka spelaren vidare.

```
function updateScore(amount) {
	score += amount;
	score_txt.text = 'Fångade: '+score;
	[b]if(score >= 10)
	{
		// We have a winner!!
		// Placera den kod som skall köras när spelaren "vunnit" här.
	}[/b]
}
```

/Mirandir

Permalänk: https://www.webforum.nu/p/1879320

---

Tråden på webben: https://www.webforum.nu/amne/flash/151572-score-10-vinst
