Square : Rectangle « Graphics « Flash / Flex / ActionScript






Square

 

package {
     
     import flash.display.Sprite;
     
     [SWF(width=550, height=400)]
     
     public class Main extends Sprite {  
     
          public function Main() {
               var square:Square = new Square();
               addChild(square);
               
               // Move to (300,300)
               square.x = 30;
               square.y = 30;
               
               // Stretch horizontally and squash vertically
               square.scaleX = 2;
               square.scaleY = 0.5;
               
               // Make 50% alpha
               square.alpha = 0.5;
               
               // Rotate 45 degrees
               square.rotation = 45;
          }
     
     }
     
}

class Square extends flash.display.Sprite {

     public function Square() {
          graphics.lineStyle(5);
          graphics.beginFill(0xFF);
          graphics.drawRect(0, 0, 100, 100);
          graphics.endFill();
     }

}

        








Related examples in the same category

1.Draw a rectangle
2.Draw Colored Rectangle
3.Fill a rectangle
4.Rotating Rectangles
5.rotateChildren( ), applies the generalized code from Example 20-4. It randomly rotates all the descendants of a specified container (not just the children).
6.A rectangle in a Sprite is nested within another Sprite. Both Sprite instances are rotated 45 degrees.