2 Replies Latest reply on Nov 8, 2007 6:36 AM by robdillon

# A really tricky application

I have an aplication that registers in mysql the number of codes a user sends. Codes from a product. the php sends to me that number in flash. I have an object that adds every time i have 5 codes. Like a bannana. 5 codes = 1 bannana, 10 codes =2 bannana and so on. I thought about dividing the number with 5 and write down that next to the bannana. But the problem is when i have 13 bannanas. then i have 2 apples and a 3 more codes. if i divide i will not get a fixed number. :| and i cant display that in the text field next to the banana.
I also have a slide bar that has 5 instances. every instance coresponds to 1,2,3,4,5 codes until it's full and i display one more bannana. There i need the 'change' from that number. For exemple if i have 7 codes i need to display 1 bannana and the slidebar at 40 percent.

Can someone tell me how can i do with those numbers?
• ###### 1. A really tricky application
hmmm. okay.
So.... in simple terms... you want the remainder after dividing by 5?

• ###### 2. Re: A really tricky application
While I'm not really following what you are attempting to do, it sounds like you want to use the integer value of the dividend and the modulus value separately. So, when you divide the number of codes by 5, you want to get back the whole number to use to display the number of bananas. And, you also want the remainder, the modulus, to use to set the slidebar position. You could do something like this:

var bananas:int = Math.floor(codes/5);
var slidebarValue:Number = codes%5;

the variable bananas will now hold a value like 0,1,2,3 etc.

the variable slidebarValue will hold a value like 0,1,2,3 etc. The difference is that the first variable tells you how many times 5 divides into the value of codes in whole number. The second variable tells you how many numbers are left over. In a normal division function, the remainder is expressed as a decimal value. For instance, 12/5 returns 2.4. You want to use that .4 separately. If you use the modulo operator (%), in Flash,you can get that number.

If you try this in Flash, trace(12%5); then you'll get back 2 in the output window. 2 is the number of numbers left over after the division of 12 by 5. So now you can use that number to set the slidebar.