Copy link to clipboard
Copied
Hello.
I want to know how i can max a calculation to a certain value. In this case its about daysCal it should when it gets down to a negative number go back to 112 and continue the calculation from there. I hope someone can help.
var dpC:DataProvider=new DataProvider()
var weeksCal = Number
var yearsCal = Number
var daysCal= Number
daysCal= (Math.floor (days-weeksCount*7))
yearsCal=yearsSb.value
weeksCal=weeksNo-weeksCount
dpC.addItem({"Weeks Training": weeksCal})
dpC.addItem({"Seasons Training":(weeksCal)/16})
dpC.addItem({"Age Training": Math.floor ((weeksCal)/16+yearsCal)+"y"+(daysCal+"d")})
dgC.dataProvider=dpC
Copy link to clipboard
Copied
Describe the factors that are involved in the calculation and where they come from.
Copy link to clipboard
Copied
I have tried this but when the sliders are used the calculation get negative after a 2 years. The first 2 years it works properly. What can cause this?
var dpC:DataProvider=new DataProvider()
var weeksCal = Number
var daysCal= Number
daysCal= (Math.floor (days-weeksCount*7))
weeksCal=weeksNo-weeksCount
dpC.addItem({"Weeks Training": weeksCal})
dpC.addItem({"Seasons Training":(weeksCal)/16})
if(daysCal<0){
years--
daysCal=daysCal+112
}
dpC.addItem({"Age Training": years+"y"+daysCal+"d"})
dgC.dataProvider=dpC
Copy link to clipboard
Copied
This is a basic function that decremtns from a given value and resets it when it reaches a certain limit:
import flash.utils.*;
var counter:int = 112;
var _timer:Timer = new Timer(100);
_timer.addEventListener(TimerEvent.TIMER,timerHandler);
_timer.start();
function timerHandler(e:TimerEvent):void{
decrementFromTo(112,0);
}
function decrementFromTo(_upperLimit:int,_lowerLimit:int):int
{
if (counter>_lowerLimit)
{
counter--;
}
else
{
counter = _upperLimit;
}
trace(counter);
return counter;
}
//try to apply this to your problem
Find more inspiration, events, and resources on the new Adobe Community
Explore Now