# Flash CS5 Actionscript 2.0 help



## someonec001 (Mar 2, 2011)

I was making this to satisfy my boredom, and when I set the variables as 1 in the onLoad function, the Random number generator works on that particular number, but when I set it as 0, it won't set itself at 1 when the appropriate key is pressed. :4-dontkno plz help me

```
/*the variables determine whether that slot number is generating or not(0=off, 1 = on)
on the .fla, there are 8 dynamic texts to display the number. the instance names are:
number1Text
number2Text
number3Text
number4Text
number5Text
number6Text
number7Text
number8Text
*/
class RNG extends MovieClip
{
	var number1;
	var number2;
	var number3;
	var number4;
	var number5;
	var number6;
	var number7;
	var number8;
	
	function onLoad()
	{
		number1 = 1;
		number2 = 0;
		number3 = 0;
		number4 = 0;
		number5 = 0;
		number6 = 0;
		number7 = 0;
		number8 = 0;
	}
	function onEnterFrame()
	{
		if ( Key.isDown(81))
		{
			if ( number1 == 0) { number1 = 1;}
			if ( number1 == 1) { number1 = 0;}
		}
		if ( Key.isDown(87))
		{
			if ( number2 == 0) { number2 = 1;}
			if ( number2 == 1) { number2 = 0;}
		}
		if ( Key.isDown(69))
		{
			if ( number3 == 0) { number3 = 1;}
			if ( number3 == 1) { number3 = 0;}
		}
		if ( Key.isDown(82))
		{
			if ( number4 == 0) { number4 = 1;}
			if ( number4 == 1) { number4 = 0;}
		}
		if ( Key.isDown(85))
		{
			if ( number5 == 0) { number5 = 1;}
			if ( number5 == 1) { number5 = 0;}
		}
		if ( Key.isDown(89))
		{
			if ( number6 == 0) { number6 = 1;}
			if ( number6 == 1) { number6 = 0;}
		}
		if ( Key.isDown(85))
		{
			if ( number7 == 0) { number7 = 1;}
			if ( number7 == 1) { number7 = 0;}
		}
		if ( Key.isDown(73))
		{
			if ( number8 == 0) { number8 = 1;}
			if ( number8 == 1) { number8 = 0;}
		}
		if ( Key.isDown(32))
		{
			if ( number1 == number2 == number3 == number4 == number5 == number6 == number7 == number8 == 1)
			{
				number1 = 0;
				number2 = 0;
				number3 = 0;
				number4 = 0;
				number5 = 0;
				number6 = 0;
				number7 = 0;
				number8 = 0;
			}
			if ( number1 == number2 == number3 == number4 == number5 == number6 == number7 == number8 == 0)
			{
				number1 = 1;
				number2 = 1;
				number3 = 1;
				number4 = 1;
				number5 = 1;
				number6 = 1;
				number7 = 1;
				number8 = 1;
			}
		}
		if ( number1 == 1){ _root.number1Text.text = Math.round((Math.random()*10 - 0.51)*1)/1;}
		if ( number2 == 1){ _root.number2Text.text = Math.round((Math.random()*10 - 0.51)*1)/1;}
		if ( number3 == 1){ _root.number3Text.text = Math.round((Math.random()*10 - 0.51)*1)/1;}
		if ( number4 == 1){ _root.number4Text.text = Math.round((Math.random()*10 - 0.51)*1)/1;}
		if ( number5 == 1){ _root.number5Text.text = Math.round((Math.random()*10 - 0.51)*1)/1;}
		if ( number6 == 1){ _root.number6Text.text = Math.round((Math.random()*10 - 0.51)*1)/1;}
		if ( number7 == 1){ _root.number7Text.text = Math.round((Math.random()*10 - 0.51)*1)/1;}
		if ( number8 == 1){ _root.number8Text.text = Math.round((Math.random()*10 - 0.51)*1)/1;}		
	}
}
```


----------



## Ninjaboi (Dec 27, 2010)

```
if ( Key.isDown(81)) { if ( number1 == 0) { number1 = 1;} if ( number1 == 1) { number1 = 0;} }
```
For that piece of code, try changing it to:


```
if ( Key.isDown(81)) { if ( number1 == 0) { number1 = 1;} else if ( number1 == 1) { number1 = 0;} }
```
Adding 'else' before 'if'. See if that works for you. If so, you might consider doing it for all the other key events.


----------



## someonec001 (Mar 2, 2011)

thanks it worked for the others, but not the one below
can u help me

```
/*if all variables are 1, it'll set them all to 0 when space is pressed. but when they are all 0, it won't set them to one*/
		if ( Key.isDown(32))
		{
			if ( number1 == number2 == number3 == number4 == number5 == number6 == number7 == number8 == 1)
			{
				number1 = 0;
				number2 = 0;
				number3 = 0;
				number4 = 0;
				number5 = 0;
				number6 = 0;
				number7 = 0;
				number8 = 0;
			}
			else if ( number1 == number2 == number3 == number4 == number5 == number6 == number7 == number8 == 0)
			{
				number1 = 1;
				number2 = 1;
				number3 = 1;
				number4 = 1;
				number5 = 1;
				number6 = 1;
				number7 = 1;
				number8 = 1;
			}
		}
```


----------



## Ninjaboi (Dec 27, 2010)

You could try changing the '==' to '&&'. Tell me if the below code works for you instead.


```
/*if all variables are 1, it'll set them all to 0 when space is pressed. but when they are all 0, it won't set them to one*/
        if ( Key.isDown(32))
        {
            if ( number1 && number2 && number3 && number4 && number5 && number6 && number7 && number8 == 1)
            {
                number1 = 0;
                number2 = 0;
                number3 = 0;
                number4 = 0;
                number5 = 0;
                number6 = 0;
                number7 = 0;
                number8 = 0;
            }
            else if ( number1 && number2 && number3 && number4 && number5 && number6 && number7 && number8 == 0)
            {
                number1 = 1;
                number2 = 1;
                number3 = 1;
                number4 = 1;
                number5 = 1;
                number6 = 1;
                number7 = 1;
                number8 = 1;
            }
        }
```


----------



## someonec001 (Mar 2, 2011)

still doesn't work. the set to 0 part works, the set to 1 doesn't


----------



## Ninjaboi (Dec 27, 2010)

We'll that if call is looking to see if ALL the number variables are equal to 0 first, then set them to 1. If even one of them are not, it will not do it. Check to make sure that all of the variables are equal to 0 first ( that also means they have to be set as 0, not just unassigned. )

EDIT: Try assigning 0 to the variables when they're declared.


```
var number1 = 0; 
var number2 = 0; 
var number3 = 0; 
var number4 = 0; 
var number5 = 0; 
var number6 = 0;
var number7 = 0; 
var number8 = 0;
```


----------



## someonec001 (Mar 2, 2011)

no doesn't work, and I also tried running it in debug, but nothing would work in debug, it only works when I'm running it normally


----------



## Ninjaboi (Dec 27, 2010)

So it works when you run it normally? Then why need to fix something that already works ( just not in debug mode )?

Also, are you sure your pressing the key that is assigned?

Key.isDown(32)

Make sure you've got the right one.


----------



## someonec001 (Mar 2, 2011)

It all works...except for the part that sets it all to 1. I'm sure it's the right key, because the set all to 0 part works fine. Though nothing at all works in debug.


----------

