1 Package2 {3 ImportFlash.display.Bitmap;4 ImportFlash.display.BitmapData;5 ImportFlash.display.DisplayObject;6 ImportFlash.display.GradientType;7 ImportFlash.display.Loader;8 ImportFlash.display.Shape;9 ImportFlash.display.Sprite;Ten Importflash.events.Event; One ImportFlash.geom.Matrix; A ImportFlash.geom.Point; - Importflash.net.URLRequest; - the /** - * ... - * @author Frost.yen - */ +[SWF (width=800, height=1000, backgroundcolor=0x000000, framerate=30)] - Public classReflectionextendsSprite + { A Private varLdr:loader=NewLoader (); at Private varPic:sprite=NewSprite (); - Public functionReflection () - { -Ldr.load (NewURLRequest ("Http://hiphotos.baidu.com/frostyen/pic/item/7e49d8b53f6b48ffd9335aa2.jpg")); - Ldr.contentLoaderInfo.addEventListener (Event.complete, onimageloaded); - } in - Private functionOnimageloaded (e:event):void to { + This. AddChild (pic); - Pic.addchild (LDR); thepic.x = 200; *PIC.Y = 10; $Ldr.scalex = Ldr.scaley =. 5;Panax NotoginsengCreateref (pic,5,0); - } the /** + * A * @param obj to create the object to be reflected the * @param the distance between the distance object and the reflection + * Offset of @param offset reflection - */ $ Private functionCreateref (obj:displayobject,distance: Number=5,offset: Number=0):void $ { - //Inverted - varBd:bitmapdata =NewBitmapData (Obj.width,obj.height,true); the varMtx:matrix =NewMatrix (); -MTX.D =-1;WuyiMtx.ty =Bd.height; the Bd.draw (obj, MTX); - Wu //add a reflection gradient - var_width:int =Bd.width; About var_height:int =Bd.height; $ -Mtx.creategradientbox (_width, _height, 0.5 * math.pi,0, offset); - varShape:shape =NewShape (); -Shape.graphics.beginGradientFill (Gradienttype.linear, [0,0,0], [0.6, 0.1, 0], [0,200, 255], MTX); AShape.graphics.drawRect (0, 0, _width, _height); + Shape.graphics.endFill (); the varMask_bd:bitmapdata =NewBitmapData (_width,_height,true, 0); - Mask_bd.draw (shape); $ //Generate final Effect theBd.copypixels (BD, Bd.rect,NewPoint (0, 0), MASK_BD,NewPoint (0, 0),false); the //Place the reflection below the object the varRef:bitmap =NewBitmap (BD); theREF.Y = obj.height + obj.y +distance; -ref.x =obj.x; in Obj.parent.addChild (ref); the } the } About the}
[ActionScript 3.0] Creating a reflection