Tutorial / Using with Flash

Code Example 4: aOut.fla

Preparation

Connect a LED to aout 0 as shown in the following schematic. Though only one LED is connected in the picture, but you can connect up to four LEDs to see all analog outputs work.

Description

In this example, "beginDrag" is called when an "onPress" event is received in instances of the symbol "bar" (from bar0 to bar3), and "endDrag" is called when an "onReleased" event is received. In the function "beginDrag," the status of each aout is set by "analogOutput" method when an "onEnterFrame" event is received.

  1. import gainer.*;
  2.  
  3. var gnr:Gainer = new Gainer("localhost", 2000, Gainer.MODE1, true);
  4.  
  5. var aoutValues:Array;
  6.  
  7. gnr.onReady = function() {
  8.     bar0.slider.onPress = function() {
  9.         beginDrag(this);
  10.     }
  11.     bar0.slider.onRelease = function() {
  12.         endDrag(this);
  13.     }
  14.     bar1.slider.onPress = function() {
  15.         beginDrag(this);
  16.     }
  17.     bar1.slider.onRelease = function() {
  18.         endDrag(this);
  19.     }
  20.     bar2.slider.onPress = function() {
  21.         beginDrag(this);
  22.     }
  23.     bar2.slider.onRelease = function() {
  24.         endDrag(this);
  25.     }
  26.     bar3.slider.onPress = function() {
  27.         beginDrag(this);
  28.     }
  29.     bar3.slider.onRelease = function() {
  30.         endDrag(this);
  31.     }
  32.  
  33.     aoutValues = new Array(4);
  34.  
  35.     this.onFinished = function() {
  36.         this.analogOutput(aoutValues);
  37.     }
  38. }
  39.  
  40. function beginDrag (obj) {
  41.     obj.startDrag(false, 0, 0, obj._parent.gauge._width-obj._width, 0);
  42.     obj.onEnterFrame = function () {
  43.         aoutValues[0] = bar0.slider._x;
  44.         aoutValues[1] = bar1.slider._x;
  45.         aoutValues[2] = bar2.slider._x;
  46.         aoutValues[3] = bar3.slider._x;
  47.     }
  48. }
  49.  
  50. function endDrag(obj) {
  51.     obj.stopDrag();
  52.     delete obj.onEnterFrame;
  53. }
prev 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 next
Print