Flash actionscript 3.0: Draw a Draggable triangle using Actionscript 3.0

Draw a Draggable triangle using Actionscript 3.0

Posted by Sankar.G | Posted in | Posted on 3:41 PM

you can draw a triangle with out any design using script copy the below script and past it in flash first Frame and run the file make a three click on the stage and drag the points


var l1:Shape=new Shape();
addChild(l1);

var p1:Sprite=new Sprite();
p1.addEventListener(MouseEvent.MOUSE_DOWN,drag1);
addChild(p1);

var p2:Sprite=new Sprite();
p2.addEventListener(MouseEvent.MOUSE_DOWN,drag2);
addChild(p2)

var p3:Sprite=new Sprite();
p3.addEventListener(MouseEvent.MOUSE_DOWN,drag3);
addChild(p3)

stage.addEventListener(MouseEvent.MOUSE_MOVE,moves);
stage.addEventListener(MouseEvent.MOUSE_UP,all);

stage.addEventListener(MouseEvent.CLICK,fun);
var boo:Number=0;
function moves(event:MouseEvent):void
{
if(boo==3)
{
l1.graphics.clear();
drawLine();
}
}
function fun(event:MouseEvent):void
{
if(boo==0)
{
p1.graphics.lineStyle(1,0x00ff00);
p1.graphics.beginFill(0x00ff00);
p1.graphics.drawCircle(0,0,5);
p3.graphics.endFill();
p1.filters=[new DropShadowFilter()];
p1.x=mouseX;
p1.y=mouseY;
boo=1
}
else if(boo==1)
{
p2.graphics.lineStyle(1,0x00ff00);
p2.graphics.beginFill(0x00ff00);
p2.graphics.drawCircle(0,0,5);
p3.graphics.endFill();
p2.filters=[new DropShadowFilter()];
p2.x=mouseX;
p2.y=mouseY;
boo=2;
}
else if(boo==2)
{
p3.graphics.lineStyle(1,0x00ff00);
p3.graphics.beginFill(0x00ff00);
p3.graphics.drawCircle(0,0,5);
p3.graphics.endFill();
p3.filters=[new DropShadowFilter()];
p3.x=mouseX;
p3.y=mouseY;
boo=3;
drawLine();
}

}
function drawLine():void
{
l1.graphics.lineStyle(1,0xffff00);
l1.graphics.moveTo(p2.x,p2.y);
l1.graphics.lineTo(p3.x,p3.y);
l1.graphics.lineTo(p1.x,p1.y);
l1.graphics.lineTo(p2.x,p2.y);
l1.filters=[new DropShadowFilter()];
l1.graphics.endFill();
}
function drag1(event:MouseEvent):void
{
if(boo==3)
{
event.currentTarget.startDrag();
}
}
function drag2(event:MouseEvent):void
{
if(boo==3)
{
event.currentTarget.startDrag();
}
}
function drag3(event:MouseEvent):void
{
if(boo==3)
{
event.currentTarget.startDrag();
}
}
function all(event:MouseEvent):void
{
stopDrag();
}

Examples:
triangle.swf

Comments (0)