Here’s a little helpful Flash AS3 sample that connects two object using Flash Actionscript 3. Drag either of the objects (the green point or the cloud popUp) and they’ll stay connected. Something like this might come in handy for a Flash map point sort of a thing or you could even motion tween the green point and have the popUP stay in the same place. This also uses the ENTER_FRAME eventListener method that calls graphics.lineTo and graphics.beginFill on frame enter.
Here’s the actionscript:
import flash.display.Shape;
import flash.display.Sprite;
import flash.display.Graphics;
//drag the two objects on the stage popup and myPoint
popup.addEventListener(MouseEvent.MOUSE_DOWN, mouseDown);
function mouseDown(event:MouseEvent):void {
popup.startDrag();
}
popup.addEventListener(MouseEvent.MOUSE_UP, mouseReleased);
function mouseReleased(event:MouseEvent):void {
popup.stopDrag();
}
myPoint.addEventListener(MouseEvent.MOUSE_DOWN, pointMouseDown);
function pointMouseDown(event:MouseEvent):void {
myPoint.startDrag();
}
myPoint.addEventListener(MouseEvent.MOUSE_UP, pointMouseRelease);
function pointMouseRelease(event:MouseEvent):void {
myPoint.stopDrag();
}
//draw the connecting shage
var triangle_mc = new Shape();
addChild(triangle_mc);
popup.addEventListener(Event.ENTER_FRAME,popUPEnter);
function popUPEnter(evt:Event) {
triangle_mc.graphics.clear();
triangle_mc.graphics.beginFill(0xFFFFFF,100);
triangle_mc.graphics.lineStyle(4,0xFFFFFF,100);
triangle_mc.graphics.moveTo(myPoint.x,myPoint.y);
triangle_mc.graphics.lineTo(myPoint.x,myPoint.y);
if (popup.y<myPoint.y) {
triangle_mc.graphics.lineTo((popup.x),(popup.y+40));
triangle_mc.graphics.lineTo((popup.x),(popup.y+80));
triangle_mc.graphics.endFill();
}
if (popup.y>myPoint.y) {
triangle_mc.graphics.lineTo((popup.x),(popup.y));
triangle_mc.graphics.lineTo((popup.x),(popup.y)+30);
triangle_mc.graphics.endFill();
}
}
Here are the source files:
anchorTest - AS3.fla
anchorTest - AS3.swf