In fact, the painting function of the code is relatively simple, it depends on whether you know. You need to dodge a few points of attention:
1, FLEX4 Application class can no longer use Addchild to add UI components, but to use AddElement (spritevisualelement) to add
Note that spritevisualelement this class is in Spark.core.SpriteVisualElement, the IDE does not automatically display the smart hint of the location of the package, which requires us to manually input. The specific post code is as follows:
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);
}
Comrades, study hard.