其实绘画功能的代码还是比较简单的,就看你知不知道了。你需要避过几个注意点:
1、flex4 中application类已经不能再使用addChild来添加ui组件,而是要用AddElement(SpriteVisualElement)来进行添加
注意了,SpriteVisualElement这个类是在spark.core.SpriteVisualElement中,IDE中无法自动显示智能提示出这个包的位置,需要我们进行手动进行输入。具体贴出代码如下:
import mx.events.FlexEvent;
import flash.geom.Matrix;
import mx.core.UIComponent;
import spark.core.SpriteVisualElement;
private function appCompHandler(event:FlexEvent):void
{
var testGrp:TestGraphics = event.target as TestGraphics;
var sprve:SpriteVisualElement = new SpriteVisualElement;
var fillType:String = GradientType.LINEAR;
var colors:Array = [0xFF0000, 0x0000FF];
var alphas:Array = [1, 1];
var ratios:Array = [0x00, 0xFF];
var matr:Matrix = new Matrix();
matr.createGradientBox(20, 20, 0, 0, 0);
var spreadMethod:String = SpreadMethod.PAD;
sprve.graphics.beginGradientFill(fillType, colors, alphas, ratios, matr, spreadMethod);
sprve.graphics.drawRect(0,0,100,100);
this.addElement(sprve);
}