Chapter 44 Example 2

by actionscriptbible
♥0 | Line 31 | Modified 2010-02-10 14:36:44 | MIT License
play

ActionScript3 source code

/**
 * Copyright actionscriptbible ( http://wonderfl.net/user/actionscriptbible )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/oHcN
 */

package {
  import flash.display.*;
  import flash.net.LocalConnection;
  public class ch44ex2 extends Sprite {
    protected var arrow:Shape;
    protected var listeningConnection:LocalConnection;
    public function ch44ex2() {
      //listening application.
      makeArrow();
      
      listeningConnection = new LocalConnection();
      listeningConnection.allowDomain("*");
      listeningConnection.client = {mouseMoved: mouseMoved};
      listeningConnection.connect("_mouseChannel");
    }
    protected function mouseMoved(newX:Number, newY:Number):void {
      arrow.x = newX;
      arrow.y = newY;
    }
    protected function makeArrow():void {
      var SIZE:Number = 20, ARROW_SIZE:Number = 9, LINE_WIDTH:Number = 4;
      arrow = new Shape();
      arrow.graphics.lineStyle(LINE_WIDTH, 0, 1, false,
        LineScaleMode.NORMAL, CapsStyle.NONE, JointStyle.MITER, ARROW_SIZE);
      arrow.graphics.moveTo(-SIZE, 0);
      arrow.graphics.lineTo(SIZE-LINE_WIDTH/2, 0);
      
      arrow.graphics.moveTo(SIZE-ARROW_SIZE, ARROW_SIZE);
      arrow.graphics.lineTo(SIZE, 0);
      arrow.graphics.lineTo(SIZE-ARROW_SIZE, -ARROW_SIZE);
      addChild(arrow);
    }
  }
}