=> Maskapp. mxml
<? 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/mx"
Xmlns: aspackage = "aspackage .*"
Minwidth = "955" minheight = "600" creationcomplete = "initfun (event )"
Pagetitle = "thestudioofcenyebao">
<FX: SCRIPT>
<! [CDATA [
Import MX. Events. flexevent;
Private function initfun (Event: flexevent): void
{
// Initialization
}
]>
</FX: SCRIPT>
<FX: declarations>
<! -- Non-visual element -->
</FX: declarations>
<S: vgroup width = "320" Height = "230" horizontalcenter = "0" verticalcenter = "0">
<Aspackage: mysprite id = "mysprite"/>
</S: vgroup>
</S: Application>
=> Mysprite.
Package aspackage
{
Import flash. display. gradienttype;
Import flash. display. loader;
Import flash. display. Sprite;
Import flash. Geom. matrix;
Import flash.net. URLRequest;
Import MX. Core. uicomponent;
Public class mysprite extends uicomponent
{
/**
* Attribute */
Public static const imgurl: String = "Public/img/girl.jpg ";
/**
* Constructor
*/
Public Function mysprite ()
{
/**
* Photo loading */
VaR Loader: loader = new loader ();
VaR URL: URLRequest = new URLRequest (imgurl );
Loader. Load (URL );
This. addchild (loader );
/**
* Draw an elliptical shape */
VaR oval: SPRITE = new sprite ();
VaR colors: array = [0x000000, 0x000000]; // black;
VaR Alphas: array = [1, 0]; // opacity _ gradient from large to small;
VaR ratios: array = [0,255]; // array of the color distribution ratio;
VaR matrix: matrix = new matrix (); // conversion matrix;
/* Parameter: width, height, rotation degree, X in the upper left corner of the rectangle, Y in the upper left corner of the rectangle */
Matrix. creategradientbox (200,100, 0,-100,-50 );
Oval. Graphics. begingradientfill (gradienttype. Radial, colors, Alphas, ratios, matrix );
Oval. Graphics. drawellipse (-100,-50,200,100 );
// The coordinates in the upper left corner of the rectangle must be the same as those in the matrix;
Oval. Graphics. endfill ();
This. addchild (Oval );
/**
* Set cache */
Loader. cacheasbitmap = true;
Oval. cacheasbitmap = true;
Loader. Mask = oval;
// Cover;
Oval. startdrag (true );
// Move;
}
}
}
=> Materials used:
Girl.jpg