AS3 to create a quadrilateral to be arbitrarily dragged

Source: Internet
Author: User
Tags addchild

main:

package {
 import as3. Mc;
 import flash.display.Sprite;
 import flash.events.Event;
 /**
  *  ....
  *  @author   ....
  */
 public class main extends sprite {
  private  var line:Sprite;
  private var mcs:Array=[];
  public function main (): void {
   line = new  Sprite ();
   addchild (line);
   init ();
  }
  private function init ()  {
   for  (var i:uint =  0; i<4; i++)  {
&NBSP;&NBSP;&NBSP;&NBSP;VAR&NBSP;MC&NBSP;=&NBSP;NEW&NBSP;MC ();
    mc.x=20*math.random () +20*i;
    mc.y=20*math.random () +20*i;
    addchild (MC);
    mcs.push (MC);
    
   }
   addeventlistener (Event.enter_frame, &NBSP;F);
  }
  private function f (e:event)  {
   line.graphics.clear ();
   line.graphics.linestyle (1);
   line.graphics.moveto (MCS[0].X,&NBSP;MCS[0].Y);
   for  (var i:uint =1; i <4; i++)  {
     line.graphics.lineto (MCS[I].X,MCS[I].Y);
   }
   line.graphics.lineto (MCS[0].X,MCS[0].Y);
  }
 }
}

Mc:

Package AS3
{
Import Flash.display.Sprite;
Import flash.events.Event;
Import flash.events.MouseEvent;

/**
* ...
* @author ...
*/
public class Mc extends Sprite
{
Public Function Mc (): void {
AddEventListener (Mouseevent.mouse_down, D);
AddEventListener (MOUSEEVENT.MOUSE_UP, u);
}
Private Function D (e:mouseevent): void{
E.currenttarget.startdrag ();
}
Private function U (e:mouseevent): void {
E.currenttarget.stopdrag ();
}


}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.