Chapter II ActionScript 3.0 learning to draw stars (mouse and keyboard events)

Source: Internet
Author: User

Today I think it is more interesting to learn, so record it ... ~ ~ ~

The following paragraph is the code that paints the stars: starshape.as

Package {Import Flash.display.shape;import Flash.display.gradienttype;public class Starshape extends Shape {public function Starshape (X:number = 5, Y:number = innerradius:number, Points:int =, = +, Outerradius:number =-angle): Number = 0, Color:uint = 0xff0000) {//x and Y are the starting point ~~var count = Math.Abs (points); This.graphics.lineStyle (2, 0x85db18);// Start Fill color this.graphics.beginFill (color), if (Count > 2) {//init Varsvar step, Halfstep, start, N, DX, dy;//calculates the distance between two points step = (M Ath. PI * 2)/points;halfstep = step/2;//start angle start = (angle/180) * Math.pi;this.graphics.moveto (x + (Math.Cos (start) * out)  Erradius), Y-(Math.sin (START) * Outerradius));//Draw The Edge for (n = 1; n <= count; n++) {dx = x + math.cos (start + (step *) of the star graph) N)-halfstep) * Innerradius;dy = Y-math.sin (start + (STEP * N)-halfstep) * Innerradius;this.graphics.lineto (dx, dy); DX = x + math.cos (start + (step * N)) * Outerradius;dy = Y-math.sin (start + (step * N)) * Outerradius;this.graphics.line to (dx, DY);}} This.graphics.endFill();}}} 

The following results are shown:

Mouse click and keyboard press event exercises (press the button is Alt,shift,ctrl, single or 22 combination, three together, click the mouse):

Source:

Samplesendandload.as
Package {Import Flash.display.sprite;import flash.events.event;import Flash.net.urlloader;import Flash.net.urlloaderdataformat;import Flash.net.urlrequest;import Flash.net.urlrequestmethod;import Flash.events.progressevent;import Flash.text.textfield;public class Samplesendandload extends Sprite {private var _ Result:textfield;public function Samplesendandload () {//Create a text box object, return to session after successful login Id_result = new TextField (); _ Result.autosize = "Left"; _result.wordwrap = True;_result.width = 300;addchild (_result);//login information, including user name and password var loginxml: XML = <login><username>kingda.org</username><password>actionscript 3</password>< /login>;var request:urlrequest = new URLRequest ("http://www.flash-mx.com/mm/login_xml.cfm"); Request.contenttype = "Text/xml"; request.data = Loginxml.toxmlstring (); Request.method = Urlrequestmethod.post;var Loader:URLLoader = new URLLoader (); Loader.addeventlistener (Event.complete, Completehandler); try {trace ("Loading ..."); Loader.load ( request);}catch (Error:argumenterror) {trace ("parameter Error");} catch (Error:securityerror) {Trace ("Security error occurred"); _result.text = "A security error occurred. \ n "+ Error;}} Private Function Completehandler (event:event): void {trace (event.target.data); var resultxml:xml = new XML ( Event.target.data); _result.text = [email protected];}}

Effect:

Can test the above click Results Oh, Hee ~ ~ Beginner Notes!! Don't puke, Auntie.

Chapter II ActionScript 3.0 learning to draw stars (mouse and keyboard events)

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.