Home | hot pepper quiz creator | Logbook |
Interactive swf Protocol
hot pepper An interactive swf file (th999.swf), incorporated in the hot pepper as a simple picture.
If you want to feel the experience, try Linos's quiz on Triangles.
the Protocol

The teacher, who wants to create Interactive swf files, must conform to the following rules.
  • First of all, the objective is to create a .swf file which will be incorporated in the hot pepper as the unique Correct picture, in a Multiple choice question with Click on icons
  • The .fla file must have a name begining with th (eg th999.fla)
  • Create a .as file with any name, eg Th999.as
  • In the Class property of the .fla file, write Th999
  • For best usage of the available space of the hot pepper quiz player, set property Size of the .fla file, to any dimensions with ratio: height / width = 0.675, eg 400 (width) x 270 (height)
  • Th999 must extend class Sprite and create 2 LocalConnection objects. conn2 for reception and conn1 for transmission
      public class Th999 extends Sprite {
        private var conn1, conn2: LocalConnection;
        private var percentageOfSuccess: Number
      }
  • The two programs (hot pepper quiz player and the Interactive swf - th999.swf) must establish a 2-way communication between them.
    To prepare for reception (red words must be used exactly as they are)
        public function Th999() {
          conn2 = new LocalConnection();
          conn2.client = this;
          try {
            conn2.connect ('HOT_PEPPER')
          } 
          catch (error: ArgumentError) {}
        }
hot pepper quiz player sends the following 4 information and th999.swf must receive them
  1. workout (Boolean). Informs th999.swf whether hot pepper quiz player is in Workout mode (true) or Testing mode (false)
  2. canAnswer (Boolean). Informs th999.swf whether the question can be answered by the pupil (true) or no (false). In the last case, the pupil just sees what he answered before.
  3. newQuestion (Boolean). Informs th999.swf whether the question is not answered (true) or is answered (false)
  4. directory (String). Informs th999.swf where is the translation file (if any). That is an optional file which must have the name th999.ii7 (the base name must be exactly the same with the base name of the .swf file and the extension must always be .ii7). If directory is empty, the file is expected to be in the folder of the current quiz. If not empty, the translation file must be searched as directory + th999.ii7
th999.swf sends the following 1 information and hot pepper quiz player receives it
  1. percentageOfSuccess (Number) A decimal number between 1 (completely correct behavior) and 0 (completely wrong behavior)
  • The receiving method must be as follows
        public function localConnectionHandler2 (workout, canAnswer, newQuestion: Boolean, directory: String): void {
          try {
            conn2.close()
          } 
          catch (error: ArgumentError) {}
          if (canAnswer) {
            conn1 = new LocalConnection();
            conn1.addEventListener (StatusEvent.STATUS, onStatus1)
          }
        }
    // -----------------------------------------------------------
        private function onStatus1 (e: StatusEvent): void {
          switch (e.level) {
            case 'status':
              break;
            case 'error':
          }
        }
  • The sending method must be as follows. It has to be activated when the pupil presses the Submit button.
        private function sendMessage (e: MouseEvent): void {
          conn1.send ('hotPepper', 'localConnectionHandler1', percentageOfSuccess);
          try {
            conn1.close()
          } 
          catch (error: ArgumentError) {}
        }
An almost complete but extremely abstract program is the following.
package {
  import flash.events.MouseEvent;
  import flash.display.Sprite;
  import flash.net.LocalConnection;
  import flash.events.StatusEvent;
  import fl.controls.Button;

  public class Th999 extends Sprite {
    private var conn1, conn2: LocalConnection;
    private var percentageOfSuccess: Number;
// ----------------------------------------------------------------------------  
    public function Th999() {
      percentageOfSuccess = 0;
      conn2 = new LocalConnection();
      conn2.client = this;
      try {
        conn2.connect ('HOT_PEPPER')
      } 
      catch (error: ArgumentError) {}

      var sendBtn: Button = new Button();
      sendBtn.label = 'Submit';
      sendBtn.addEventListener (MouseEvent.CLICK, sendMessage);
      addChild (sendBtn)
    }
// ----------------------------------------------------------------------------
    private function sendMessage (e: MouseEvent): void {
      conn1.send ('hotPepper', 'localConnectionHandler1', percentageOfSuccess);
      try {
        conn1.close()
      } 
      catch (error: ArgumentError) {}
    }
// ----------------------------------------------------------------------------
    public function localConnectionHandler2 (workout, canAnswer, newQuestion: Boolean, directory: String): void {
      try {
        conn2.close()
      } 
      catch (error: ArgumentError) {}
      if (canAnswer) {
         conn1 = new LocalConnection();
         conn1.addEventListener (StatusEvent.STATUS, onStatus1)
      }
    }
// ----------------------------------------------------------------------------
    private function onStatus1 (e: StatusEvent): void {
      switch (e.level) {
        case 'status':
          break;
        case 'error':
      }
    }
// ----------------------------------------------------------------------------
  }
}