Flash / Flex / ActionScript/Graphics/Circle — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
Admin (обсуждение | вклад) м (1 версия) |
(нет различий)
|
Текущая версия на 08:15, 26 мая 2010
Содержание
Circle Clicker
package {
import flash.display.*;
import flash.events.*;
public class Main extends Sprite {
public function Main() {
stage.addEventListener(MouseEvent.CLICK, clickListener);
}
private function clickListener (e:MouseEvent):void {
if (e.target == stage) {
drawCircle(e.stageX, e.stageY);
} else {
removeChild(DisplayObject(e.target));
}
}
public function drawCircle (x:int, y:int):void {
var randomColor:int = Math.floor(Math.random( )*0xFFFFFF);
var randomSize:int = 10 + Math.floor(Math.random( )*150);
var circle:Sprite = new Sprite( )
circle.graphics.beginFill(randomColor, 1);
circle.graphics.lineStyle( );
circle.graphics.drawEllipse(0, 0, randomSize, randomSize);
circle.x = x-randomSize/2;
circle.y = y-randomSize/2;
addChild(circle);
}
}
}
Create a circle shape
package {
import flash.display.*;
public class DisplayListExample extends Sprite {
public function DisplayListExample( ) {
var red:Shape = createCircle( 0xFF0000, 10 );
red.x = 10;
red.y = 20;
var green:Shape = createCircle( 0x00FF00, 10 );
green.x = 15;
green.y = 25;
var blue:Shape = createCircle( 0x0000FF, 10 );
blue.x = 20;
blue.y = 20;
var container1:Sprite = new Sprite( );
container1.addChild( red );
container1.addChild( green );
container1.addChild( blue );
addChild( container1 );
var container2:Sprite = new Sprite( );
addChild( container2 );
container2.addChild( red );
}
public function createCircle( color:uint, radius:Number ):Shape {
var shape:Shape = new Shape( );
shape.graphics.beginFill( color );
shape.graphics.drawCircle( 0, 0, radius );
shape.graphics.endFill( );
return shape;
}
}
}
Create Rectangle and Circle
package {
import flash.display.*;
import flash.text.TextField;
public class GreetingApp extends Sprite {
public function GreetingApp( ) {
var rectAndCircle:Shape = new Shape( );
rectAndCircle.graphics.lineStyle(1);
rectAndCircle.graphics.beginFill(0x0000FF, 1);
rectAndCircle.graphics.drawRect(125, 0, 150, 75);
rectAndCircle.graphics.beginFill(0xFF0000, 1);
rectAndCircle.graphics.drawCircle(50, 100, 50);
rectAndCircle.x = 125;
rectAndCircle.y = 100;
addChild(rectAndCircle);
var greeting_txt:TextField = new TextField( );
greeting_txt.text = "Hello world";
greeting_txt.x = 200;
greeting_txt.y = 300;
addChild(greeting_txt);
}
}
}
Creating Custom Visual Classes
package {
import flash.display.Sprite;
import flash.display.Shape;
public class Main extends Sprite {
public function Main( ) {
var red:Circle = new Circle( 0xFF0000, 10 );
red.x = 10;
red.y = 20;
var green:Circle = new Circle( 0x00FF00, 10 );
green.x = 15;
green.y = 25;
var blue:Circle = new Circle( 0x0000FF, 10 );
blue.x = 20;
blue.y = 20;
addChild( red );
addChild( green );
addChild( blue );
}
}
}
class Circle extends flash.display.Shape {
private var _color:uint;
private var _radius:Number;
public function Circle( color:uint = 0x000000, radius:Number = 10 ) {
_color = color;
_radius = radius;
draw( );
}
private function draw( ):void {
graphics.beginFill( _color );
graphics.drawCircle( 0, 0, _radius );
graphics.endFill( );
}
}
Fill a circle
package {
import flash.display.GradientType;
import flash.display.Sprite;
import flash.geom.Matrix;
public class Main extends Sprite {
public function Main() {
var colors:Array = [];
var pMatrix:Matrix = new Matrix();
pMatrix.createGradientBox(70, 70, 0, -45, -32);
graphics.beginGradientFill(GradientType.RADIAL, [0xFF0000,0x330000], [1,1], [0,0xFF], pMatrix);
graphics.drawCircle(0, 0, 25);
graphics.endFill();
}
}
}