## 3D Color Code Calculator in Away3DLite

Color Code Calculator

I did this example to demonstrate how to interactively change the materials of a Collada file in Away3DLite. I build the model in Cinema4D and assigned bands and added colors to those bands. I looked up their names in the out putted Collada file and then assigned materials as requested form the Flash Builder ComboBox using change event methods.

Demo

Video

Source

Code Discussion

Here’s example code for the first ComboBox

 private function changeEvt1(e:Event):void { myOne = e.currentTarget.selectedIndex; modelResistor.materialLibrary.getMaterial(“ID18”).material = myMatArray[myOne]; calcMyOhms(); }

Code for Calculator Ohms as discussed on the video.

 private function calcMyOhms():void { myOhms = (myOne*10 + myTwo)*Math.pow(10, multiplier[myThree]); if (myOhms >= 1000000) { myOhms /= 1000000; myOutput.text = “Resistance = “ + String(myOhms) + ” MOhms, “ + tolerance[myFour]; } else { if (myOhms >= 1000) { myOhms /= 1000; myOutput.text = “Resistance = “ + String(myOhms) + ” KOhms, “ + tolerance[myFour]; } else { myOutput.text = “Resistance = “ + String(myOhms) + ” Ohms, “ + tolerance[myFour]; }}}

A similar 2D example was done on the web by

http://www.dannyg.com/examples/res2/resistor.htm

Enjoy!

private function changeEvt1(e:Event):void {

myOne = e.currentTarget.selectedIndex;

modelResistor.materialLibrary.getMaterial(“ID18”).material = myMatArray[myOne];

calcMyOhms();

}

private function changeEvt2(e:Event):void {

myTwo = e.currentTarget.selectedIndex;

modelResistor.materialLibrary.getMaterial(“ID8”).material = myMatArray[myTwo];

calcMyOhms();

}

private function changeEvt3(e:Event):void {

myThree = e.currentTarget.selectedIndex;

modelResistor.materialLibrary.getMaterial(“ID23”).material = myMatArray[myThree];

calcMyOhms();

}

private function changeEvt4(e:Event):void {

myFour = e.currentTarget.selectedIndex;

modelResistor.materialLibrary.getMaterial(“ID13”).material = myPerArray[myFour];

calcMyOhms();

}