标签:
今天觉得学到的比较有趣,所以记录之......~~~
下面这段就是画出星星的代码:StarShape.as
package { import flash.display.Shape; import flash.display.GradientType; public class StarShape extends Shape { public function StarShape (x:Number = 50, y:Number = 50, points:int = 5, innerRadius:Number = 20, outerRadius:Number = 50, angle:Number = 0, color:uint = 0xff0000) {//x和y是起始点~~ var count = Math.abs(points); this.graphics.lineStyle(2, 0x85DB18); //开始填色 this.graphics.beginFill(color); if (count > 2) { //init vars var step, halfStep, start, n, dx, dy; //计算两点之间的距离 step = (Math.PI * 2) / points; halfStep = step / 2; //起始角度 start = (angle / 180) * Math.PI; this.graphics.moveTo(x + (Math.cos(start) * outerRadius), y - (Math.sin(start) * outerRadius)); //画星状图的边 for (n = 1; n <= count; n++) { dx = x + Math.cos(start + (step * 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.lineTo(dx, dy); } } this.graphics.endFill(); } } }
具体显示效果如下:
鼠标点击和键盘按下事件练习(按下的按键是Alt,Shift,Ctrl,单个或两两组合,三个一起,同时点击鼠标):
源码:
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() { //建立一个文本框对象,登录成功后返回SESSION ID _result = new TextField(); _result.autoSize = "left"; _result.wordWrap = true; _result.width = 300; addChild(_result); //登录信息,包含用户名和密码 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("参数错误"); }catch (error:SecurityError) { trace("发生安全错误"); _result.text = "发生安全错误。\n" + error; } } private function completeHandler(event:Event):void { trace(event.target.data); var resultXML:XML = new XML(event.target.data); _result.text = resultXML.@sessionid; } } }
效果:
可以测试一下上面的点击结果哦,嘻嘻~~新手笔记!!大婶别吐。
第二章 ActionScript 3.0学习之画星星(鼠标及键盘事件)
标签:
原文地址:http://www.cnblogs.com/xianfangloveyangmei/p/4425589.html