Tutorial / Using with Flash

Code Example 3: dOut.fla

Preparation

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

Description

In this example, function "dOut" is called when an "onRelease" event is received in instances of "onoff" (from d0 to d3).

  1. import gainer.*;
  2.  
  3. var gnr:Gainer = new Gainer("localhost", 2000, Gainer.MODE1, true);
  4.  
  5. dArray = [false, false, false, false];
  6.  
  7. gnr.onReady = function() {
  8.     d0.onRelease = function() {
  9.         dOut(this);
  10.     }
  11.     d1.onRelease = function() {
  12.         dOut(this);
  13.     }
  14.     d2.onRelease = function() {
  15.         dOut(this);
  16.     }
  17.     d3.onRelease = function() {
  18.         dOut(this);
  19.     }
  20. }
  21.  
  22. function dOut(obj) {
  23.     if (obj._currentframe == 1) {
  24.         obj.gotoAndStop(2);
  25.     } else {
  26.         obj.gotoAndStop(1);
  27.     }
  28.     dArray[obj._name.substr(1, 1)] = !dArray[obj._name.substr(1, 1)];
  29.     gnr.digitalOutput(dArray);
  30. }
prev 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 next
Print