If you are going to create a flow diagram or a white board application, you might need a line which acts like an elastic string, where as user can drag both end. So I have created for one of my project and thought, it might help someone to save some time. Here are the classes
elasticLine.as
package com.collectivezen{
import flash.display.DisplayObject;
import flash.display.Graphics;
import flash.display.Shape;
import flash.display.Sprite;
import flash.display.MovieClip;
import com.collectivezen.RoundRectangle;
import flash.filters.*;
public class elasticLine extends MovieClip {
private var rrX:Number;
private var rrY:Number;
private var rrWidth:Number;
private var rrHeight:Number;
private var bgColor:uint;
private var borderColor:uint;
private var borderSize:Number;
private var child:MovieClip = new MovieClip();
private var src:RoundRectangle;
private var dest:RoundRectangle;
private var _this:elasticLine;
private var lineDrawing:MovieClip = new MovieClip();
public function elasticLine(rrX:Number=0,rrY:Number=0,rrWidth:Number=10,rrHeight:Number=10,bgColor:uint=0x000000) {
this.rrX=rrX;
this.rrY=rrY;
this.rrWidth=rrWidth;
this.rrHeight=rrHeight;
this.bgColor=bgColor;
lineDrawing = new MovieClip();
lineDrawing.graphics.lineStyle(1, 0x000000, 1 );
lineDrawing.graphics.beginFill( bgColor, 1 );
lineDrawing.graphics.moveTo(rrX,rrY);
lineDrawing.graphics.lineTo(rrWidth,rrHeight);
///Glow Filter
var glow:GlowFilter = new GlowFilter();
glow.color = bgColor;
glow.alpha = 1;
glow.blurX = 8;
glow.blurY = 8;
var dropShadow:DropShadowFilter = new DropShadowFilter();
dropShadow.color = 0x000000;
dropShadow.blurX = 8;
dropShadow.blurY = 8;
dropShadow.angle = 0;
dropShadow.alpha = 0.5;
dropShadow.distance = 10;
var filtersArray:Array = new Array(glow, dropShadow);
lineDrawing.filters = filtersArray;
addChild(lineDrawing);
}
public function moveLine(src:RoundRectangle,dest:RoundRectangle) {
lineDrawing.graphics.clear();
lineDrawing.graphics.lineStyle(1, 0x000000, 1 );
lineDrawing.graphics.beginFill( this.bgColor, 1 );
lineDrawing.graphics.moveTo(src._CurCenX,src._CurCenY);
lineDrawing.graphics.lineTo(dest._CurCenX,dest._CurCenY);
///Glow Filter
var glow:GlowFilter = new GlowFilter();
glow.color = this.bgColor;
glow.alpha = 1;
glow.blurX = 8;
glow.blurY = 8;
var dropShadow:DropShadowFilter = new DropShadowFilter();
dropShadow.color = 0x000000;
dropShadow.blurX = 8;
dropShadow.blurY = 8;
dropShadow.angle = 0;
dropShadow.alpha = 0.5;
dropShadow.distance = 10;
var filtersArray:Array = new Array(glow, dropShadow);
lineDrawing.filters = filtersArray;
}
public function drawLine(_X:uint,_Y:uint,_eX:uint,_eY:uint,_col:uint) {
lineDrawing.graphics.clear();
lineDrawing.graphics.lineStyle(1, 0x000000, 1 );
lineDrawing.graphics.beginFill( _col, 1 );
lineDrawing.graphics.moveTo(_X,_Y);
lineDrawing.graphics.lineTo(_eX,_eY);
///Glow Filter
var glow:GlowFilter = new GlowFilter();
glow.color = _col;
glow.alpha = 1;
glow.blurX = 8;
glow.blurY = 8;
var dropShadow:DropShadowFilter = new DropShadowFilter();
dropShadow.color = 0x000000;
dropShadow.blurX = 8;
dropShadow.blurY = 8;
dropShadow.angle = 0;
dropShadow.alpha = 0.5;
dropShadow.distance = 10;
var filtersArray:Array = new Array(glow, dropShadow);
lineDrawing.filters = filtersArray;
}
}
}
See my different post to get com.collectivezen.RoundRectangle
No comments:
Post a Comment