Flash Code for Capacitors in Series

 

 

 

 

         

Shown below is a 'running' Macromedia Flash program for computing the effective resistance of capacitors in series. Likewise shown below the program window is the Flash code used for the application, for reference by students learning to program in Flash in the context of electronics engineering. This Flash program accepts several different values of capacitance, and outputs their effective capacitance in series connection. Each capacitance value may be added by using the blank provided and pressing the 'add' button beside it. The effective capacitance output is updated every time a new capacitance is added.

 

To try the program, input the values 330 and 470.  This will result in an output of 193.88, which means that the two capacitors' effective capacitance in series is 193.88.  Now add a third input, say, 1000. The output will be updated once again to 162.39,  which is the equivalent capacitance of the three capacitance values (330, 470, 1000) in series connection.  

 

  

mx.accessibility.ButtonAccImpl.enableAccessibility();
var Divisor:Number=0;
var Dividend:Number=0;
var FirstItem:Boolean=true;
  
function AddCap() {

     if (Numeric(txtCap.text)) {
          lstCap.addItem(txtCap.text);
          Divisor += parseFloat(txtCap.text);
          if (FirstItem) {
              Dividend = parseFloat(txtCap.text);
              FirstItem = false;
              lblCap.text = "Capacitance : " + FormatNumber(parseFloat(txtCap.text));
              Dividend = parseFloat(txtCap.text);}
          else{
               Dividend *= parseFloat(txtCap.text);
               var Ans:Number;
               Ans = Dividend/Divisor;
               lblCap.text = "Capacitance : " + FormatNumber(Ans);
               Dividend = Ans;
               Divisor = Ans;};};
      txtCap.text = "";};
  
function Numeric(sText):Boolean {
     if (sText == parseFloat(sText,10))
          {return true}
     else
          {return false};};
  
function Clearlist() {
     lstCap.removeAll();
     FirstItem = true;
     Divisor = 0;
     Dividend = 0;
     lblCap.text = "Capacitance :";};
  
cmdAdd.addEventListener("click", AddCap);
cmdClear.addEventListener("click", Clearlist);
  
function FormatNumber (amount, isDec) {
     if (isNan(amount)) {
          return NaN;}
     if (isDec != "isDec") {
          amount = amount*100;
          amount = Math.round(amount);}
     amount = String(Math.floor(amount));
     if (amount.length == 1) {
          return ("0.0"+amount);}
     if (amount.length == 2) {
          return ("0."+amount);}
     dec = amount.slice(-2);
     amount = amount.substring(0, amount.length-2);
     tmpNum = [];
     do {
          tmpNum.push(amount.slice(-3));
          amount = amount.substring(0, amount.length-3);}

     while (amount.length>3);
     if (amount.length) {
          tmpNum.push(amount);}
     tmpNum.reverse();
     return (tmpNum.join() + "." + dec);}