A Flash Developer Resource Site

# Thread: [LITTLE HELP] Create an "up-down" variable

1. ## [LITTLE HELP] Create an "up-down" variable

Hello everybody!
I need a variable to go up from 1 to 100, once at 100 go down back to 1, and so on, up and down.
What is the best and easiest way to do it?

Thanks a lot!

2. The simplest would probably just to set the variable manually. A nice way to do that with one statement would be like this:
Code:
`i=(i==1)?100:1;`

3. Hi Swak, that only returns 1, 100, 1, 100, 1 ...and so on.
Not the numbers between.
I might be not clear indeed.
I need a variable that returns "1,2,3,4,5,6,7,8,9...37..68...99,100 AND GO DOWN 99,98,97,96....6,5,4,3,2,1 AND GO UP AGAIN
Thanks anyways

4. wow i=(i==1)?100:1; looks really cool how can you call a function with that? I have tried countless times to use that question mark

5. tonaz79
I see, there's a simple way of doing that then.
Code:
```var i:int = 1;
var c:int = 1;
function count ():void {
i +=  c;
switch (i) {
case 100 :
c = -1;
break;
case 1 :
c = 1;
break;
}
}```
This is the basic idea. I just used an enterFrame function to continuously call the count() function.

Alloy Bacon
The ? is not a function really. It's more like they took an if statement and turned it into an operator like the +-*/ symbols. Bascially you have 3 parts for it to work.
s1?s2:s3
s1 needs to be a bool. If s1 is true then it returns s2. Otherwise it returns s3.
Here's an example: i=false?1:2;
with that i will be equal to 2. If it's true then i will equal 1.
I like it, it makes for a simple operator when you understand it. In fact you can use it for a if else shorthand.
Here's an example: false?trace("1"):trace("2");
That will always trace 2.

6. Thats almost like .bat syntax

7. If everything's good please add a "[RESOLVED][LITTLE HELP] Create an "up-down" variable" tag. Thanks!

8. lol no like bat. echo

9. lol who ever uses that syntax to type must look like this or something because thats not normal:

10. now you be silly allooy.
you say it look like .bat code, i say it not look like .bat code, you just want answer things when not right.

http://www.instructables.com/id/5-Cool-Batch-Files/

11. now you be silly allooy.
you say it look like .bat code, i say it not look like .bat code, you just want answer things when not right.

http://www.instructables.com/id/5-Cool-Batch-Files/

good self pic you have, allieoony baccoony

12. ��

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

 » Home » Movies » Tutorials » Submissions » Board » Links » Reviews » Feedback » Gallery » Fonts » The Lounge » Sound Loops » Sound FX » About FK » Sitemap