17 July 2011

AS3: Wave of values class function - produces incremental and decremental values

Sometimes it's necessary to have a value increment until it gets to a certain point and then have it decrement again in a wave shape. A simple Math.sin() calculation will work in some cases but its not easy to control the increment using that method. This handy & simple class makes it quick and easy to do just this. There's lots of room for improvements & additions so feel free to post updates :)


Please see right hand pane before copying my code- thanks! >

package com.cron {
 
 public class valueWave {
  private var inc,startno,counter,max,min //counter is always>0
  public var num //latest value
  
  public function valueWave($min:Number=0, $max:Number=10, $increment:Number=1, $startno:Number=0 ) {
   if($max<$min){
    trace("valueWave ERROR: max must be greater than min")
    return
   }
   inc=$increment
   startno=$startno
   counter=$startno
   num=$startno
   max=$max
   min=$min
  }
  
  public function next(){
   if(max==0){return(num);} //disable if max and min are the same
   num = Math.abs((counter % (2*(max-min))) - (max-min)) + min;
   counter += inc;
   return(num)
  }
  
  public function reset(){
   counter=startno
  }
  
 }
 
}

//USAGE::
//the code above should be saved as [your root class path]/com/cron/valueWave.as
import com.cron.valueWave

var W=new valueWave(1,10,1,5);

addEventListener(Event.ENTER_FRAME,function(){
    trace(W.next());
})

//OUTPUTS:
5,4,3,2,1,2,3,4,5,6,7,8,9,10,9,8,7,6,5,etc

16 comments:

Juliana Kho said...

1
2 sabung ayam
3
4
5 daftar scr888 indonesia
6 slot osg777
7
8

Susan said...

Eminem is an American songwriter, rapper, record producer and an actor. Hе hаѕ also bееn dеѕсrіbеd аѕ оnе оf thе grеаtеѕt hір-hор аrtіѕtѕ оf аll tіmе, оnе оf thе grеаtеѕt rарреrѕ оf аll tіmе аnd was lіѕtеd іn Rоllіng Ѕtоnе lіѕt оf 100 grеаtеѕt аrtіѕtѕ оf аll tіmе аt number 83. Here are a few more interesting facts and Eminem net worth you might not have known.

Madrid Software Trainings said...

Best Software Training Institute in Delhi Madrid Software offers strategic training paths for the certification skills required to support today's technologies, while offering a Business Analytic course, Data science courses in Delhi, Career in AI and Digital Marketing Course in Delhi for clients looking to implement new/upgraded business applications.

Cricket Mazza 11 Live Line & Fastest IPL Score said...

Download Cricket Mazza 11 for Android Live Line & Fastest IPL Score. Get Live Cricket Scores, Scorecard, Commentary, Match Info and Schedules of All International & Domestic Matches, Series wise Stats, Records, Analysis and Facts, Trending News and Tweets, Recent ICC Player and Team Rankings. Also Download live cricket score apps for ios, including Beach Cricket, Cricket T20 Fever 3D, Download Real Cricket mazza 11 and other top answers suggested and ranked.

Business Tips said...

SEO experts is a team ready to develop your business locally and internationally.We are as highly innovative technology company that has taken upon the task of providing technical solutions in the modern world of New Media to our clients.As a leading SEO specialist in karachi we are honoured to partner with reputable companies to help them to grow their business professionally.

Virtualmindinfotech said...

Virtualmindinfotech is a Full-Stack Digital Transformation Company. We provide Digital Marketing Service, Website Design service in Noida, Web Development Services in Noida, Ecommerce Web Development Services that will increase your website traffic, conversion rate and overall revenue. Contact us for more info.

Unknown said...

Aas leading pro digital marketing agency in karachi, we are honoured to partner with reputable companies to help them to grow their business professionaly.

Nick said...

Thanks for sharing the article.

sara laurence said...

In order to get the best and most professional web development services contact web design agency Dallas as they have the best and most professional web developers.

Web Design Gator said...

A Content Management System (CMS) is an online device that allows you to deal with all parts of your website - route, content, topics, and substantially more. Web Design Company In Los Angeles offers you undertaking CMS Website Development through a Microsoft system just as open-source innovations.

sara laurence said...

The way you have explained the topic is just simply amazing and in case if you need some professional ghost writer than royal book writers are the best as they have the most professional writers.

Live Logo Creator said...

We Proudly Offer the Best Logos to All Free of Charge As an industry chief, we give top notch answers for all. Live Logo Creator is only one of the few free and premium advanced arrangements we give to clients around the world. Get in touch with us to find out about our computerized arrangements and how we can assist you with succeeding.

Super Logo Designs said...

The way you described the issue is fantastic, and if you need a professional logo designer, Custom Logo Design Services is the greatest option because they have the finest designers.

Trails And Tails Doodles said...

Trails & Tails Doodles was chosen as our name because we believe Aussiedoodle and Goldendoodles are ideal partners for all of your outdoor excursions, no matter which path you select.

Royal Book Writers said...

Your description of the problem is excellent, and if you want a professional E Book Writer, Book Writing Services is the best alternative because they use the best Book Writers.

Anonymous said...

Your description of the problem is good, and Sanitizing Cleaning Services is the finest option because they use the best staff.

Post a Comment

Cron Design Studio: Dublin based web design & software development