Skip to main content
June 2, 2013
Question

How can i max a calculation value?

  • June 2, 2013
  • 1 reply
  • 543 views

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

This topic has been closed for replies.

1 reply

Ned Murphy
Legend
June 2, 2013

Describe the factors that are involved in the calculation and where they come from.

June 2, 2013

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

Inspiring
June 3, 2013

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