package { import flash.display.Bitmap; import flash.display.BitmapData; import flash.display.Loader; import flash.display.LoaderInfo; import flash.display.Sprite; import flash.events.Event; import flash.net.URLRequest; [SWF(width=800, height=200, backgroundColor=0xFFFFFF)] /** * Demonstrates the use of the T component of the UVT data and how it can be used to correct perspective distortion. */ public class graphic_flex_image_effects_01_Flex_DrawTrianglesUVTTest extends Sprite { private var _image:BitmapData; /** * Constructor. Loads the specified image. */ public function graphic_flex_image_effects_01_Flex_DrawTrianglesUVTTest() { var loader:Loader = new Loader(); loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onImageLoaded); loader.load(new URLRequest("../../assets/checkers.png")); } /** * Draws polygon on left with no perspective correction. */ private function drawImage1():void { var vertices:Vector. = new Vector.(); vertices.push(80, 0); vertices.push(320, 0); vertices.push(400, 200); vertices.push(0, 200); var indices:Vector. = new Vector.(); indices.push(1, 0, 3); indices.push(1, 3, 2); // uvtData does not contain T information var uvtData:Vector. = new Vector.(); uvtData.push(0, 0); uvtData.push(1, 0); uvtData.push(1, 1); uvtData.push(0, 1); graphics.beginBitmapFill(_image); graphics.drawTriangles(vertices, indices, uvtData); graphics.endFill(); } /** * Draws polygon on right with perspective correction. */ private function drawImage2():void { var vertices:Vector. = new Vector.(); vertices.push(480, 0); vertices.push(720, 0); vertices.push(800, 200); vertices.push(400, 200); var indices:Vector. = new Vector.(); indices.push(1, 0, 3); indices.push(1, 3, 2); // uvtData contains T information var uvtData:Vector. = new Vector.(); uvtData.push(0, 0, 0.6); uvtData.push(1, 0, 0.6); uvtData.push(1, 1, 1); uvtData.push(0, 1, 1); graphics.beginBitmapFill(_image); graphics.drawTriangles(vertices, indices, uvtData); graphics.endFill(); } /** * Handler for when image loads. Calls methods to draw polygons. */ private function onImageLoaded(event:Event):void { var loaderInfo:LoaderInfo = event.target as LoaderInfo; var bitmap:Bitmap = loaderInfo.content as Bitmap; _image = bitmap.bitmapData; drawImage1(); drawImage2(); } } }