1
var square:Sprite = new Sprite();
addChild(square);
square.graphics.lineStyle(3,0x00ff00);
square.graphics.beginFill(0x0000FF);
square.graphics.drawRect(0,0,100,100);
square.graphics.endFill();
square.x = stage.stageWidth/2-square.width/2;
square.y = stage.stageHeight/2-square.height/2;
//simple_shape.as
package{
import flash.display.Sprite;
public class simple_shape extends Sprite{
var square:Sprite;
public function simple_shape(){
square = new Sprite();
addChild(square);
square.graphics.lineStyle(3,0x00ff00);
square.graphics.beginFill(0x0000FF);
square.graphics.drawRect(0,0,100,100);
square.graphics.endFill();
square.x = stage.stageWidth/2-square.width/2;
square.y = stage.stageHeight/2-square.height/2;
}}
}
2
var square:Sprite = new Sprite();
addChild(square);
square.graphics.lineStyle(3,0x00ff00);
square.graphics.beginFill(0x0000FF);
square.graphics.drawRoundRect(0,0,100,100,20);
square.graphics.endFill();
square.x = stage.stageWidth/2-square.width/2;
square.y = stage.stageHeight/2-square.height/2;
var package{
import flash.display.Sprite;
public class simple_rounded_shape extends Sprite{
var square:Sprite;
public function simple_rounded_shape(){
square = new Sprite();
addChild(square);
square.graphics.lineStyle(3,0x00ff00);
square.graphics.beginFill(0x0000FF);
square.graphics.drawRoundRect(0,0,100,100,20);
square.graphics.endFill();
square.x = stage.stageWidth/2-square.width/2;
square.y = stage.stageHeight/2-square.height/2;
}}
}
3
var square:Sprite = new Sprite();
addChild(square);
square.graphics.lineStyle(3,0x00ff00);
square.graphics.beginFill(0x0000FF);
drawShape(square);
square.graphics.endFill();
square.x = stage.stageWidth/2-square.width/2;
square.y = stage.stageHeight/2-square.height/2;
function drawShape(sprite:Sprite):void{
sprite.graphics.lineStyle(3,0x00ff00);
sprite.graphics.beginFill(0x0000FF);
sprite.graphics.moveTo(0,0);
sprite.graphics.lineTo(100,0);
sprite.graphics.lineTo(100,100);
sprite.graphics.lineTo(0,100);
sprite.graphics.lineTo(0,0);
sprite.graphics.endFill();
}
package{
import flash.display.Sprite;
public class simple_lineTo_shape extends Sprite{ var square:Sprite; public function simple_lineTo_shape(){
square = new Sprite();
addChild(square);
square.graphics.lineStyle(3,0x00ff00);
square.graphics.beginFill(0x0000FF);
drawShape(square);
square.graphics.endFill();
square.x = stage.stageWidth/2-square.width/2;
square.y = stage.stageHeight/2-square.height/2;
}
private function drawShape(sprite:Sprite):void{
sprite.graphics.lineStyle(3,0x00ff00);
sprite.graphics.beginFill(0x0000FF);
sprite.graphics.moveTo(0,0);
sprite.graphics.lineTo(100,0);
sprite.graphics.lineTo(100,100);
sprite.graphics.lineTo(0,100);
sprite.graphics.lineTo(0,0);
sprite.graphics.endFill();
}}
}
4
var arrayOfLittleSquare:Array = new Array();
var Xpos:Number = 50;
var Ypos:Number = 50;
for(var i:uint = 0; i<4; i++){
var littleSquare:Sprite = new Sprite();
addChild(littleSquare);
arrayOfLittleSquare.push(littleSquare);
littleSquare.graphics.beginFill(0x000000);
drawShape(littleSquare,10,10);
littleSquare.graphics.endFill();
littleSquare.x = Xpos;
littleSquare.y = Ypos;
Xpos+=100;
if(Xpos>150){
Xpos = 50;
Ypos+=100;
}
}
function drawShape(sprite:Sprite,Width:Number, Height:Number):void{
sprite.graphics.moveTo(-Width/2,-Height/2);
sprite.graphics.lineTo(Width/2,-Height/2);
sprite.graphics.lineTo(Width/2,Height/2);
sprite.graphics.lineTo(-Width/2,Height/2);
sprite.graphics.lineTo(-Width/2,-Height/2);
}
5
var arrayOfLittleSquare:Array = new Array();
var Xpos:Number = 50;
var Ypos:Number = 50;
var square:Sprite = new Sprite();//new line
addChild(square);//new line
for(var i:uint = 0; i<4; i++){
var littleSquare:Sprite = new Sprite();
addChild(littleSquare);
arrayOfLittleSquare.push(littleSquare);
littleSquare.graphics.beginFill(0x000000);
drawShape(littleSquare,10,10);
littleSquare.graphics.endFill();
littleSquare.x = Xpos;
littleSquare.y = Ypos;
Xpos+=100;
if(Xpos>150){
Xpos = 50;
Ypos+=100;
}}
drawDynamicShape(square);//new line function drawShape(sprite:Sprite,Width:Number, Height:Number):void{
sprite.graphics.moveTo(-Width/2,-Height/2);
sprite.graphics.lineTo(Width/2,-Height/2);
sprite.graphics.lineTo(Width/2,Height/2);
sprite.graphics.lineTo(-Width/2,Height/2);
sprite.graphics.lineTo(-Width/2,-Height/2);
}
function drawDynamicShape(sprite:Sprite):void{//new function
sprite.graphics.clear();
sprite.graphics.beginFill(0x0000FF);
sprite.graphics.moveTo(arrayOfLittleSquare[0].x,arrayOfLittleSquare[0].y);
sprite.graphics.lineTo(arrayOfLittleSquare[1].x,arrayOfLittleSquare[1].y);
sprite.graphics.lineTo(arrayOfLittleSquare[3].x,arrayOfLittleSquare[3].y);
sprite.graphics.lineTo(arrayOfLittleSquare[2].x,arrayOfLittleSquare[2].y);
sprite.graphics.lineTo(arrayOfLittleSquare[0].x,arrayOfLittleSquare[0].y);
sprite.graphics.endFill();
}
6
var arrayOfLittleSquare:Array = new Array();
var Xpos:Number = 50;
var Ypos:Number = 50;
var square:Sprite = new Sprite();
addChild(square);
for(var i:uint = 0; i<4; i++){
var littleSquare:Sprite = new Sprite();
addChild(littleSquare);
arrayOfLittleSquare.push(littleSquare);
littleSquare.graphics.beginFill(0x000000);
drawShape(littleSquare,10,10);
littleSquare.graphics.endFill();
littleSquare.x = Xpos;
littleSquare.y = Ypos;
Xpos+=100;
if(Xpos>150){
Xpos = 50;
Ypos+=100;
}
arrayOfLittleSquare[i].addEventListener(MouseEvent.MOUSE_DOWN, dragSquares);//new line
arrayOfLittleSquare[i].addEventListener(MouseEvent.MOUSE_UP, stopSquares);//new line
}
drawDynamicShape(square) function dragSquares(e:MouseEvent):void{//new function
e.target.startDrag();
}
function stopSquares(e:MouseEvent):void{//new function
e.target.stopDrag();
}
function drawShape(sprite:Sprite,Width:Number, Height:Number):void{
sprite.graphics.moveTo(-Width/2,-Height/2);
sprite.graphics.lineTo(Width/2,-Height/2);
sprite.graphics.lineTo(Width/2,Height/2);
sprite.graphics.lineTo(-Width/2,Height/2);
sprite.graphics.lineTo(-Width/2,-Height/2);
}
function drawDynamicShape(sprite:Sprite):void{
sprite.graphics.clear();
sprite.graphics.beginFill(0x0000FF);
sprite.graphics.moveTo(arrayOfLittleSquare[0].x,arrayOfLittleSquare[0].y);
sprite.graphics.lineTo(arrayOfLittleSquare[1].x,arrayOfLittleSquare[1].y);
sprite.graphics.lineTo(arrayOfLittleSquare[3].x,arrayOfLittleSquare[3].y);
sprite.graphics.lineTo(arrayOfLittleSquare[2].x,arrayOfLittleSquare[2].y);
sprite.graphics.lineTo(arrayOfLittleSquare[0].x,arrayOfLittleSquare[0].y);
sprite.graphics.endFill();
}
7
var arrayOfLittleSquare:Array = new Array();
var Xpos:Number = 50;
var Ypos:Number = 50;
var square:Sprite = new Sprite();
addChild(square);
for(var i:uint = 0; i<4; i++){
var littleSquare:Sprite = new Sprite();
addChild(littleSquare);
arrayOfLittleSquare.push(littleSquare);
littleSquare.graphics.beginFill(0x000000);
drawShape(littleSquare,10,10);
littleSquare.graphics.endFill();
littleSquare.x = Xpos;
littleSquare.y = Ypos;
Xpos+=100;
if(Xpos>150){
Xpos = 50;
Ypos+=100;
}
arrayOfLittleSquare[i].addEventListener(MouseEvent.MOUSE_DOWN, dragSquares);
arrayOfLittleSquare[i].addEventListener(MouseEvent.MOUSE_UP, stopSquares);
}
drawDynamicShape(square);
function dragSquares(e:MouseEvent):void{
e.target.startDrag();
e.target.addEventListener(Event.ENTER_FRAME, redrawShape);//new line
}
function stopSquares(e:MouseEvent):void{
e.target.stopDrag();
e.target.removeEventListener(Event.ENTER_FRAME, redrawShape);//new line
}
function drawShape(sprite:Sprite,Width:Number, Height:Number):void{
sprite.graphics.moveTo(-Width/2,-Height/2);
sprite.graphics.lineTo(Width/2,-Height/2);
sprite.graphics.lineTo(Width/2,Height/2);
sprite.graphics.lineTo(-Width/2,Height/2);
sprite.graphics.lineTo(-Width/2,-Height/2);
}
function redrawShape(e:Event):void{//new function that we use to call the drawDynamicShape function
drawDynamicShape(square);
}
function drawDynamicShape(sprite:Sprite):void{
sprite.graphics.clear();
sprite.graphics.beginFill(0x0000FF);
sprite.graphics.moveTo(arrayOfLittleSquare[0].x,arrayOfLittleSquare[0].y);
sprite.graphics.lineTo(arrayOfLittleSquare[1].x,arrayOfLittleSquare[1].y);
sprite.graphics.lineTo(arrayOfLittleSquare[3].x,arrayOfLittleSquare[3].y);
sprite.graphics.lineTo(arrayOfLittleSquare[2].x,arrayOfLittleSquare[2].y);
sprite.graphics.lineTo(arrayOfLittleSquare[0].x,arrayOfLittleSquare[0].y);
sprite.graphics.endFill();
}
8
package{ import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.events.Event; public class simple_lineTo_dynamic_shape extends Sprite{ var arrayOfLittleSquare:Array = new Array();
var Xpos:Number = 50;
var Ypos:Number = 50;
var square:Sprite = new Sprite(); public function simple_lineTo_dynamic_shape(){ addChild(square);
for(var i:uint = 0; i<4; i++){
var littleSquare:Sprite = new Sprite();
addChild(littleSquare);
arrayOfLittleSquare.push(littleSquare);
littleSquare.graphics.beginFill(0x000000);
drawShape(littleSquare,10,10);
littleSquare.graphics.endFill();
littleSquare.x = Xpos;
littleSquare.y = Ypos;
Xpos+=100;
if(Xpos>150){
Xpos = 50;
Ypos+=100;
}
arrayOfLittleSquare[i].addEventListener(MouseEvent.MOUSE_DOWN, dragSquares);
arrayOfLittleSquare[i].addEventListener(MouseEvent.MOUSE_UP, stopSquares);
}
drawDynamicShape(square)
}
function dragSquares(e:MouseEvent):void{
e.target.startDrag();
e.target.addEventListener(Event.ENTER_FRAME, redrawShape);
}
function stopSquares(e:MouseEvent):void{
e.target.stopDrag();
e.target.removeEventListener(Event.ENTER_FRAME, redrawShape);
}
function drawShape(sprite:Sprite,Width:Number, Height:Number):void{
sprite.graphics.moveTo(-Width/2,-Height/2);
sprite.graphics.lineTo(Width/2,-Height/2);
sprite.graphics.lineTo(Width/2,Height/2);
sprite.graphics.lineTo(-Width/2,Height/2);
sprite.graphics.lineTo(-Width/2,-Height/2);
}
function redrawShape(e:Event):void{
drawDynamicShape(square);
}
function drawDynamicShape(sprite:Sprite):void{
sprite.graphics.clear();
sprite.graphics.beginFill(0x0000FF);
sprite.graphics.moveTo(arrayOfLittleSquare[0].x,arrayOfLittleSquare[0].y);
sprite.graphics.lineTo(arrayOfLittleSquare[1].x,arrayOfLittleSquare[1].y);
sprite.graphics.lineTo(arrayOfLittleSquare[3].x,arrayOfLittleSquare[3].y);
sprite.graphics.lineTo(arrayOfLittleSquare[2].x,arrayOfLittleSquare[2].y);
sprite.graphics.lineTo(arrayOfLittleSquare[0].x,arrayOfLittleSquare[0].y);
sprite.graphics.endFill();
}}
}
facebook
twitter
google+
fb share