actionscript 3 - as3 getting object coordinates -


hello have piece of code witch creates circles, , after move them function want center coordinates can draw lines center center of circles, don`t have idea how ... if can suggest me 1 , here code witch creates circle :

function new_sond(event:mouseevent):void {     if (i<9)     {     i++;     q=i;     var btn:sprite = new sprite();       btn.graphics.beginfill(0x0099ff, 1);     btn.graphics.drawcircle(400, 300, 15);     btn.graphics.endfill();     var s:string = string(q);     btn.name=s;      var textfield = new textfield();     textfield.mouseenabled=false;     textfield.text = i;     textfield.width = 10;      textfield.height = 17;     textfield.x = 395; // center horizontally     textfield.y = 292; // center vertically     btn.addchild(textfield);     this.addchild(btn);     } } 

the code mooving them :

this.addeventlistener(mouseevent.mouse_down, mousedownh); this.addeventlistener(mouseevent.mouse_up, mouseuph);  function mousedownh(evt:mouseevent):void {     var object = evt.target;     object.startdrag(); }  function mouseuph(evt:mouseevent):void {     var obj = evt.target;         obj.stopdrag(); } 

and code draw lines between them :

function click1(e:mouseevent):void{     e.currenttarget.removeeventlistener(mouseevent.click, click1);     var i:int;     i=1;     if (e.target.name!=null){     trace(e.target.name);     sx=mousex;     sy=mousey;     stage.addeventlistener(mouseevent.click,click2);     } }  function click2(e:mouseevent):void{     e.currenttarget.removeeventlistener(mouseevent.click, click2);     fx=mousex;     fy=mousey;     var i:int;     i=2;     trace(e.target.name);     var  line:shape = new shape();     line.graphics.linestyle(1,0x0066ff,1);     line.graphics.moveto(sx,sy);     line.graphics.lineto(fx,fy);     this.addchild(line);     var inputfield:textfield = new textfield();     inputfield.border = true;     inputfield.type = textfieldtype.input;     str=inputfield.text;     trace(str);     inputfield.width = 23;     inputfield.height = 18;     inputfield.x = (sx+fx)/2;     inputfield.y = (sy+fy)/2;     addchild(inputfield); } 

the thing want draw line center center, mousex , mousey coordinates draw, because don`t know how take center coordinates of object.... : http://gyazo.com/6003630d549209ec5e16ccfffe0ee689 want lines drawn center, if has suggestions please help

sorry long post, don`t know need put piece center them wanted give hole code can placed.... appreciate idea .

well, if drew circle @ 0,0 , moved btn object .x , .y 400,300 this:

btn.graphics.drawcircle(0,0,15); btn.x = 400; btn.y = 300; 

then drag btn around screen, btn.x , btn.x (or in click handler, e.target.x , e.target.y) center of circle.

alternately, if can't or don't want way, can bounds of btn (with respect this coordinate system, since that's line being drawn), , since it's circle, center of bounds center of circle:

var btn:sprite = e.target; var bounds:rectangle = btn.getbounds(this); var center_x:number = bounds.x + bounds.width/2; var center_y:number = bounds.y + bounds.height/2; 

Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -