Flex Graphics
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/halo"
minWidth="1024" minHeight="768" xmlns:mx1="library://ns.adobe.com/flex/mx">
<fx:Script>
<![CDATA[
import flash.geom.Matrix;
/*
画图形之前必要调用的函数(其中之一即可):
linestyle()、beginFill()、lineGradientStyle()、beginGradientFill()、beginBitmapFill()方法来设置线条样式和/或填充。
*/
//画矩形
private function rect(rectX:Number, rectY:Number, rectWidth:Number, rectHeight:Number):void{
rectBoxID.graphics.clear();
if(radioLineID.selected){ //线性
rectBoxID.graphics.lineStyle(20, 0xFF0000, 1.0, false, LineScaleMode.VERTICAL, CapsStyle.NONE, JointStyle.MITER, 100);
}else if(radioGradientID.selected){ //渐变
var matr:Matrix = new Matrix();
matr.createGradientBox(20, 20, 0, 0, 0);
//the last parameter can selete three type: SpreadMethod.PAD or SpreadMethod.REFLECT or SpreadMethod.REPEAT.
rectBoxID.graphics.beginGradientFill(GradientType.LINEAR, [0xFF0000, 0x00FF00], [1, 1], [0x00, 0xFF], matr, SpreadMethod.REPEAT);
}else if(radioFullID.selected){ //填充
rectBoxID.graphics.beginFill(0xFF0000, 1.0);
}
rectBoxID.graphics.drawRect(rectX, rectY, rectWidth, rectHeight);
//
}
//画圆角矩形
private function circleRect(cRectX:Number, cRectY:Number, cRectWidth:Number, cRectHeight:Number, cRectDU:Number):void{
cRectBoxID.graphics.clear();
if(radioLineID.selected){ //线性
cRectBoxID.graphics.lineStyle(20, 0xFF0000, 1.0, false, LineScaleMode.VERTICAL, CapsStyle.NONE, JointStyle.MITER, 100);
}else if(radioGradientID.selected){ //渐变
//the last parameter can selete three type: SpreadMethod.PAD or SpreadMethod.REFLECT or SpreadMethod.REPEAT.
cRectBoxID.graphics.beginGradientFill(GradientType.LINEAR, [0xFF0000, 0x0000FF], [1, 0.1], [0, 255], new Matrix(), SpreadMethod.PAD);
rectBoxID.graphics.endFill();
}else if(radioFullID.selected){ //填充
cRectBoxID.graphics.beginFill(0xFF0000, 1.0);
}
cRectBoxID.graphics.drawRoundRect(cRectX, cRectY, cRectWidth, cRectHeight, cRectDU);
}
//画直线
private function line(lineX:Number, lineY:Number):void{ //两个参数都表示从起始的位置坐标x、y相加这两个参数后值就是结束的x、y值
lineBoxID.graphics.clear();
if(radioLineID.selected){ //线性
lineBoxID.graphics.lineStyle(20, 0xFF0000, 1.0, false, LineScaleMode.VERTICAL, CapsStyle.NONE, JointStyle.MITER, 100);
}else if(radioGradientID.selected){ //渐变
lineBoxID.graphics.lineStyle(20, 0xFF0000, 1.0, false, LineScaleMode.VERTICAL, CapsStyle.NONE, JointStyle.MITER, 100);
lineBoxID.graphics.lineGradientStyle(GradientType.LINEAR, [0xFF0000, 0x0000FF], [1, 0.5], [0, 255], new Matrix(), SpreadMethod.PAD);
}else if(radioFullID.selected){ //(填充)直线不存在填充的,呵呵
lineBoxID.graphics.lineStyle(20, 0xFF0000, 1.0, false, LineScaleMode.VERTICAL, CapsStyle.NONE, JointStyle.MITER, 100);
}
lineBoxID.graphics.lineTo(lineX, lineY);
}
//画曲线
private function cLine(endX:Number, endY:Number):void{
cLineBoxID.graphics.clear();
if(radioLineID.selected){ //线性
cLineBoxID.graphics.lineStyle(20, 0xFF0000, 1.0, false, LineScaleMode.VERTICAL, CapsStyle.NONE, JointStyle.MITER, 100);
}else if(radioGradientID.selected){ //渐变
var matr:Matrix = new Matrix();
matr.createGradientBox(20, 20, 0, 0, 0);
cLineBoxID.graphics.beginGradientFill(GradientType.LINEAR, [0xFF0000, 0x00FF00, 0xFF0000], [0.2, 1, 1], [0, 128, 255], matr, SpreadMethod.REFLECT);
}else if(radioFullID.selected){ //填充
cLineBoxID.graphics.beginFill(0xFF0000);
}
cLineBoxID.graphics.curveTo(100, 80, endX, endY); //前两个参数表示弧度的偏移量,后两个参数表示结束点的x、y坐标
}
//画圆
private function circle(oX:Number, oY:Number, radius:Number):void{
circleBoxID.graphics.clear();
if(radioLineID.selected){ //线性
circleBoxID.graphics.lineStyle(20, 0xFF0000, 1.0, false, LineScaleMode.VERTICAL, CapsStyle.NONE, JointStyle.MITER, 100);
}else if(radioGradientID.selected){ //渐变
var matr:Matrix = new Matrix();
matr.createGradientBox(20, 20, 0, 0, 0);
circleBoxID.graphics.beginGradientFill(GradientType.LINEAR, [0xFF0000, 0x00FF00, 0xFF0000], [0.2, 1, 1], [0, 128, 255], matr, SpreadMethod.REFLECT, "rgb", 0.7);
}else if(radioFullID.selected){ //填充
circleBoxID.graphics.beginFill(0xFF0000);
}
circleBoxID.graphics.drawCircle(oX, oY, radius);
}
//画椭圆
private function tCircle(x:Number, y:Number, tWidth:Number, tHeight:Number):void{
tCircleBoxID.graphics.clear();
if(radioLineID.selected){ //线性
tCircleBoxID.graphics.lineStyle(20, 0xFF0000, 1.0, false, LineScaleMode.VERTICAL, CapsStyle.NONE, JointStyle.MITER, 100);
}else if(radioGradientID.selected){ //渐变
var matr:Matrix = new Matrix();
matr.createGradientBox(20, 20, 0, 0, 0);
//the last parameter can selete three type: SpreadMethod.PAD or SpreadMethod.REFLECT or SpreadMethod.REPEAT.
tCircleBoxID.graphics.beginGradientFill(GradientType.LINEAR, [0xFF0000, 0x00FF00], [1.0, 1.0], [0x00, 0xFF], matr, SpreadMethod.REPEAT);
}else if(radioFullID.selected){ //填充
tCircleBoxID.graphics.beginFill(0xFF0000);
}
tCircleBoxID.graphics.drawEllipse(x, y, tWidth, tHeight);
}
]]>
</fx:Script>
<!--画矩形-->
<mx1:Button id="rectButID" x="500" y="50" label="画矩形" click="rect(100, 20, 250, 50);"/>
<mx1:Box id="rectBoxID"/>
<!--画圆角矩形-->
<mx1:Button id="cRectButID" x="500" y="120" label="画圆角矩形" click="circleRect(100, 100, 300, 80, 50);"/>
<mx1:Box id="cRectBoxID"/>
<!--画直线-->
<mx1:Button id="lineButID" x="500" y="250" label="画直线" click="line(350, 0);"/>
<mx1:Box id="lineBoxID" x="50" y="250"/>
<!--画曲线-->
<mx1:Button id="cLineButID" x="500" y="350" label="画曲线" click="cLine(300, 0);"/>
<mx1:Box id="cLineBoxID" x="100" y="300"/>
<!--画圆-->
<mx1:Button id="circleButID" x="500" y="450" label="画圆" click="circle(250, 450, 50);"/>
<mx1:Box id="circleBoxID"/>
<!--画椭圆-->
<mx1:Button id="tCircleButID" x="500" y="550" label="画椭圆" click="tCircle(120, 520, 150, 50);"/>
<mx1:Box id="tCircleBoxID"/>
<mx1:RadioButton id="radioLineID" x="600" y="50" label="线性"/>
<mx1:RadioButton id="radioGradientID" x="750" y="50" label="渐变" selected="true"/>
<mx1:RadioButton id="radioFullID" x="900" y="50" label="填充"/>
</s:Application>
Flex Graphics的更多相关文章
- arcgis for flex全国地图天气预报的具体实现过程解析
系统架构是B/S,开发语言是flex,开发工具是myeclise或者flashbuild,通过调用百度提供的在线天气预报web api接口的方式来实现. 采用地图是ArcGIS全国地图,开发接口为ar ...
- FLEX的动画
1.使用自带效果 在Flex里面不像在Flash里面随意制作动画了,Flex更趋向于应用程序,而不是动画制作了,所以没有了时间轴的概念.在Flex中使用动画效果,可以用Flex自带的Effect,或者 ...
- FLEX 特效
一.简介: flex特效是ria应用程序的rich的重要组成部分. EffectManager类管理所有的特效实例以避免不必要的定时器和方法调用造成的内内存使用过大.一个效果由两部分组成:一是效果的E ...
- Flex AdvancedDatagrid使用
首先我先来看下利用Advanced Datagrid做出的效果,然后我们再对其中所利用的知识进行讲解,效果图如下: 我们来看下这个效果我们所用到的关于Advanced Datagrid的相关知识: 一 ...
- Flex开发自定义控件
前期准备: 点击File菜单 -> New -> MXML Component,然后弹出一个对话框. 在对话框中输入组件名,选择此组件继承的类型,如:Canvas,DataGrid,Com ...
- flex 生命周期 ibm引用
Flex 本质 提起 Flex 我们不得不追述其发展历史以及两个很重要的名词或者说技术,那就是 Flash 和 Flash Player.Flash 是 Adobe 推出的基于时间轴的交互式矢量图和 ...
- Flex里的命名空间,fx、mx、s【转】
Flex 4带给我们的,是全新的命名空间.了解这些命名空间必定是一件好事情.Flex 4有三个非常重要的命名空间,分别是: xmlns:fx=”http://ns.adobe.com/mxml/200 ...
- Flex显示麦克风当前音量
Flex动态显示麦克风当前音量 效果: 代码: <?xml version="1.0" encoding="utf-8"?> <s:Appli ...
- flex 图片旋转(解决公转和自转问题)
在Flex中图片的旋转是既有公转和自转的.这样在图片旋转的时候就有一定小麻烦: 为了更好地说明问题,先引入两个概念:“自转”和“公转”.想象一下,地球在绕着太阳公转的同时,它自己也在自转.Flash应 ...
随机推荐
- 模拟远程HTTP的POST请求
建立请求,以模拟远程HTTP的POST请求方式构造并获取处理结果 /// <summary> /// 建立请求,以模拟远程HTTP的POST请求方式构造并获取处理结果 /// </s ...
- ASP Session的功能的缺陷(进程外的Session)
目前ASP的开发人员都正在使用Session这一强大的功能,但是在他们使用的过程中却发现了ASP Session有以下缺陷: 进程依赖性:ASP Session状态存于IIS的进程中,也就是ineti ...
- Dapper.Contrib.Extensions问题
Dapper.Contrib.Extensions问题 Dapper.Extension.1.0.0.1\lib\net45\Dapper.Extension.dll Dapper.Contrib.1 ...
- 十二生肖查询网页版制作(php)
今天无聊做了一个十二生肖查询器: 预览网址效果:http://hongxing01.hktd02u.me48.com/03Sxcx 源代码下载:http://down.51cto.com/data/1 ...
- 【Oracle 12c】CUUG OCP认证071考试原题解析(32)
32.choose the best answer View the Exhibit and examine the data in EMP and DEPT tables. In the DEPT ...
- jquery中通过添加readonly或者disabled属性实现行为禁止 / 去除某个属性的方法
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Display all 2232 possibilities? (y or n)
Linux下我在没输入任何命令的情况下摁了两下tab键,然后就出现了这个提示:Display all 2232 possibilities? (y or n) 我觉得摁y的话就会显示所有的现阶段命令. ...
- javascript获取网址参数
通过以上图片,就可以很好的理解: location.href location.protocol location.host location.hostname location.port locat ...
- J2SE基本安装和java的环境变量
J2SE基本安装和java的环境变量 1. 首先登录http://www.oracle.com,下载JDK(J2SE) JDK有很多版本其中JDK 1.0,1.1,1.2,1.3,1.4 1.5 ...
- Word2Vec原理及代码
一.Word2Vec简介 Word2Vec 是 Google 于 2013 年开源推出的一款将词表征为实数值向量的高效工具,采用的模型有CBOW(Continuous Bag-Of-Words,连续的 ...