/********************************************************************************************************/ /* This section of the program controls the return button on the page. The button instance is named */ /* return120. */ /********************************************************************************************************/ return120.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndPlayFromFrame_12); function fl_ClickToGoToAndPlayFromFrame_12(event:MouseEvent):void { gotoAndPlay(80); } /********************************************************************************************************/ /* End Return Button Section */ /********************************************************************************************************/ /********************************************************************************************************/ /* Variable Declaration Section */ /* */ /********************************************************************************************************/ /********************************************************************************************************/ /* Initial Resistance Values in Ohms */ /********************************************************************************************************/ var R1=3; var R2=3; var R3=3; var R4=3; /********************************************************************************************************/ /* Initial Resistor Position Values (0=3ohms, 1=6 ohms, 2=Infinite Ohms 3=zero ohms) */ /********************************************************************************************************/ var R1pos=0; var R2pos=0; var R3pos=0; var R4pos=0; /********************************************************************************************************/ /* Initial Meter Values (circuit voltage is zero initially) */ /********************************************************************************************************/ var v1=0; var v2=0; var v3=0; var v4=0; var v5=0; var a1=0; var a2=0; var a3=0; /********************************************************************************************************/ /* Initial Calculated Resistance Values in Ohms */ /********************************************************************************************************/ var RTotal=5; var RL1=6; var RL2=3; var RL3=3; var RPara=2; /********************************************************************************************************/ /* Initial System Values */ /********************************************************************************************************/ var voltage=0.0; var sysCurrent=0; /********************************************************************************************************/ /* Control Variables */ /********************************************************************************************************/ var initialler=0; var selectMe = -1; var shortMe=0; var openMe=0; /********************************************************************************************************/ /* Create Initial Display (One time only) */ /********************************************************************************************************/ if (initialler==0) { displayMe(); initialler=1; } /********************************************************************************************************/ /* Voltage Button Controls */ /*This portion of the problem selects the appropriate voltage when a user selects a voltage button */ /*Upon making a selection the other two voltage buttons are rendered inop by using the hideOthers */ /*function. The selectMe variable toggles between negative one and positive one for control */ /********************************************************************************************************/ volt9.addEventListener(MouseEvent.CLICK, hideOthers1); function hideOthers1(event:MouseEvent):void { selectMe=selectMe*-1; /*Event Toggle*/ if (selectMe == 1){ /* 9 Volt switch goes from off to on */ voltage=9.0; /* Set System Voltage Value*/ volt6.visible = false; /*Disable other buttons*/ volt3.visible = false; renewMe();} /*Calculate & Display new values based on changes*/ else { /* 9 Volt switch goes from on to off */ voltage=0.0; /* Set System Voltage Value*/ volt6.visible = true; /*Enable other buttons*/ volt3.visible = true; renewMe();} /*Calculate & Display new values based on changes*/ } volt6.addEventListener(MouseEvent.CLICK, hideOthers2); function hideOthers2(event:MouseEvent):void { selectMe=selectMe*-1; /*Event Toggle*/ if (selectMe == 1){ /* 6 Volt switch goes from off to on */ voltage=6.0; /* Set System Voltage Value*/ volt9.visible = false; /*Disable other buttons*/ volt3.visible = false; renewMe();} /*Calculate & Display new values based on changes*/ else { /* 6 Volt switch goes from on to off */ voltage=0.0; /* Set System Voltage Value*/ volt9.visible = true; /*Enable other buttons*/ volt3.visible = true; renewMe();} /*Calculate & Display new values based on changes*/ } volt3.addEventListener(MouseEvent.CLICK, hideOthers3); function hideOthers3(event:MouseEvent):void { selectMe=selectMe*-1; /*Event Toggle*/ if (selectMe == 1){ /* 3 Volt switch goes from off to on */ voltage=3.0; /* Set System Voltage Value*/ volt6.visible = false; /*Disable other buttons*/ volt9.visible = false; renewMe();} /*Calculate & Display new values based on changes*/ else { /* 3 Volt switch goes from on to off */ voltage=0.0; /* Set System Voltage Value*/ volt6.visible = true; /*Enable other buttons*/ volt9.visible = true; renewMe();} /*Calculate & Display new values based on changes*/ } /********************************************************************************************************/ /* Resistor Knob Controls */ /*This portion of the problem selects the appropriate resistance when a user selects a resistance knob */ /* */ /********************************************************************************************************/ Resistor1.addEventListener(MouseEvent.CLICK, ValueR1); function ValueR1(event:MouseEvent):void { R1pos=R1pos+1; /*Knob virtually advances*/ if(R1pos==4){R1pos=0;} /* Reset Knob when it comes all the way around */ if(R1pos==0) {R1=3;} if(R1pos==1) {R1=6;} if(R1pos==2) {R1=999;} if(R1pos==3) {R1=0;} renewMe(); /*Calculate & Display new values based on changes*/ } Resistor2.addEventListener(MouseEvent.CLICK, ValueR2); function ValueR2(event:MouseEvent):void { R2pos=R2pos+1; if(R2pos==4){R2pos=0;} if(R2pos==0) {R2=3;} if(R2pos==1) {R2=6;} if(R2pos==2) {R2=999;} if(R2pos==3) {R2=0;} renewMe(); } Resistor3.addEventListener(MouseEvent.CLICK, ValueR3); function ValueR3(event:MouseEvent):void { R3pos=R3pos+1; if(R3pos==4){R3pos=0;} if(R3pos==0) {R3=3;} if(R3pos==1) {R3=6;} if(R3pos==2) {R3=999;} if(R3pos==3) {R3=0;} renewMe(); } Resistor4.addEventListener(MouseEvent.CLICK, ValueR4); function ValueR4(event:MouseEvent):void { R4pos=R4pos+1; if(R4pos==4){R4pos=0;} if(R4pos==0) {R4=3;} if(R4pos==1) {R4=6;} if(R4pos==2) {R4=999;} if(R4pos==3) {R4=0;} renewMe(); } function renewMe():void{ calcLegs(); if (shortMe==1) {gotoAndPlay(180);} /* Short Circuit Situation - Go To Short Circuit Page */ if (openMe==1) {zeroMe();} /* Open circuit - No Current Flow - Therefore all values are zero */ if (voltage==0) {zeroMe();} /* No Voltage present - Therefore all values are zero */ if (shortMe==0 && openMe==0 && voltage!=0) { /* There is an actual circuit go and calculate values */ sysCurrent=voltage/RTotal; /* Calculate System current by dividing voltage by resistance */ a1=sysCurrent; /* Value for a1 ammeter */ v1=sysCurrent*RL3; /* Voltage drop across first resistor */ if(RL1==-1) { /* Either R3 or R4 are open therefore no current flowing through this branch of the circuit */ v3=0; v4=0; v5=0; a3=0; v2=sysCurrent*RL2; /* All current flows through middle leg of circuit */ a2=sysCurrent; } if(RL2==-1) { /* R2 is open therefore no current flowing through this branch of the circuit */ v3=sysCurrent*R3; v4=sysCurrent*RL1; v5=sysCurrent*R4; a3=sysCurrent; /* All current flows through far right leg of circuit */ v2=0; a2=0; } if(RL2!=-1 && RL1!=-1) { /* Current flows through both legs of circuit */ a2=sysCurrent*(RL1/(RL1+RL2)); /* Current is proportional to resistance in each leg (Kirchhoffs Proportional Law) */ a3=sysCurrent*(RL2/(RL1+RL2)); v2=a2*RL2 /* Calculate voltage drops */ v3=a3*R3; v4=a3*RL1; v5=a3*R4; } truncateMe(); } openMe=0; } /********************************************************************************************************/ /* calcLegs Function */ /*This portion of the problem selects the appropriate voltage when a user selects a voltage button */ /*Upon making a selection the other two voltage buttons are rendered inop by using the hideOthers */ /*function. The selectMe variable toggles between negative one and positive one for control */ /********************************************************************************************************/ function calcLegs():void{ if (R3pos==2 || R4pos==2) {RL1=-1;} else {RL1=R3+R4;} if (R2pos==2) {RL2=-1;} else {RL2=R2;} if (R1pos==2) {RL3=-1;} else {RL3=R1;} if (RL1!=-1 && RL2!=-1) {RPara=(RL1*RL2)/(RL1+RL2);} if (RL1==-1 && RL2==-1) {RPara=-1;} if (RL1==-1 && RL2!=-1) {RPara=RL2;} if (RL2==-1 && RL1!=-1) {RPara=RL1;} if (RL3==0 && RPara==0) {shortMe=1;} if (RL3==-1 || RPara==-1) {openMe=1;} if (shortMe==0 && openMe==0) {RTotal=RL3+RPara;} } /********************************************************************************************************/ /* zeroMe Function */ /* */ /* Sets all values to zero and then calls on the display function */ /* */ /********************************************************************************************************/ function zeroMe():void{ v1=0; v2=0; v3=0; v4=0; v5=0; a1=0; a2=0; a3=0; displayMe(); } function truncateMe():void{ v1= int((v1)*100)/100; v2= int((v2)*100)/100; v3= int((v3)*100)/100; v4= int((v4)*100)/100; v5= int((v5)*100)/100; a1= int((a1)*100)/100; a2= int((a2)*100)/100; a3= int((a3)*100)/100; displayMe(); } function displayMe():void{ DisAmps1.text=String(a1); DisAmps2.text=String(a2); DisAmps3.text=String(a3); DisVolts1.text=String(v1); DisVolts2.text=String(v2); DisVolts3.text=String(v3); DisVolts4.text=String(v4); DisVolts5.text=String(v5); }