Flash / Flex / ActionScript/Graphics/Triangle

Материал из Web эксперт
Перейти к: навигация, поиск

Creates the triangle

 
package {
  import flash.display.GradientType;
  import flash.display.Sprite;
  import flash.geom.Matrix;
       
  public class Main extends Sprite {
  
       public function Main() {
          graphics.lineStyle(1);
          graphics.beginFill(0x00FF00, 1);
          graphics.moveTo(25, 0);
          graphics.lineTo(50, 25);
          graphics.lineTo(0, 25);
          graphics.lineTo(25, 0);
          graphics.endFill(  );
  
       }
  
  }
}



Draws a red triangle with a five pixel-thick black outline. Notice that the default start point matches the endpoint

 
package{
  import flash.display.*;
  
  public class Main extends Sprite{
    public function Main(){
        var triangle:Shape = new Shape(  );
        triangle.graphics.beginFill(0xFF0000, 1);
        triangle.graphics.lineStyle(20);
        triangle.graphics.lineTo(125, 125); // Draw a line down and right
        triangle.graphics.lineTo(250, 0);   // Draw a line up and right
        triangle.graphics.lineTo(0, 0);     // Draw a line left
        triangle.graphics.endFill(  );
        addChild(triangle);
    }
  }
}



MouseEvent.MOUSE_MOVE: Handling MouseEvent.MOUSE_MOVE over a triangle

 
package {
  import flash.display.*;
  import flash.events.*;
  public class Main extends Sprite {
    public function Main (  ) {
      // Create the triangle
      var triangle:Sprite = new Sprite(  );
      triangle.graphics.lineStyle(1);
      triangle.graphics.beginFill(0x00FF00, 1);
      triangle.graphics.moveTo(25, 0);
      triangle.graphics.lineTo(50, 25);
      triangle.graphics.lineTo(0, 25);
      triangle.graphics.lineTo(25, 0);
      triangle.graphics.endFill(  );
      triangle.x = 200;
      triangle.y = 100;
      addChild(triangle);
      triangle.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveListener);
    }
    private function mouseMoveListener (e:MouseEvent):void {
      trace("mouse move");
    }
  }
}



Registers mouseMoveListener( ) to be executed whenever the mouse moves while the mouse pointer is over the Sprite object referenced by the variable triangle.

 
package{
    import flash.display.GradientType;
    import flash.display.Sprite;
    import flash.geom.Matrix;
    
    public class Ball extends Sprite {
    
         public function Ball() {
            var triangle:Sprite = new Sprite(  );
            triangle.graphics.lineStyle(1);
            triangle.graphics.beginFill(0x00FF00, 1);
            triangle.graphics.moveTo(25, 0);
            triangle.graphics.lineTo(50, 25);
            triangle.graphics.lineTo(0, 25);
            triangle.graphics.lineTo(25, 0);
            triangle.graphics.endFill(  );
            triangle.x = 200;
            triangle.y = 100;
            
            // Register with triangle for MouseEvent.MOUSE_MOVE events
            triangle.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveListener);
    
         }// ...elsewhere in the class, define the listener
        private function mouseMoveListener (e:MouseEvent):void {
          trace("mouse move");
        }
    }
}