[ActionScript 3.0] Creating a reflection

Source: Internet
Author: User
Tags addchild

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.