aether.swc

时间:2014-12-21 03:39:49
【文件属性】:
文件名称:aether.swc
文件大小:29KB
文件格式:SWC
更新时间:2014-12-21 03:39:49
截屏 as aether swc 实现AS截屏不能少的库。这个库需要与as3corelib.swc一起使用。 下面是代码部分: package { import aether.utils.ScreenCapture; import com.adobe.images.JPGEncoder; import flash.display.BitmapData; import flash.display.Sprite; import flash.events.MouseEvent; import flash.geom.Rectangle; import flash.net.FileReference; import flash.utils.ByteArray; [SWF(width=800,height=600,backgroundColor=0xffffff)] public class PrintScreen extends Sprite { private var bitmapData:BitmapData; public function PrintScreen() { //画了一些随机的矢量图 graphics.lineStyle(1); graphics.drawRect(0,0,100,100); for(var i:int=0;i<30;i++){ var tempx:Number=Math.random()*400; var tempy:Number=Math.random()*300; var color:Number=0xff0000*Math.random(); graphics.lineStyle(1,color); graphics.lineTo(tempx,tempy); graphics.endFill(); } //定义截屏的区域,并保存在bitmapData中 //false是位图是否有transparent项 var region:Rectangle= new Rectangle(0, 0, 100, 100); bitmapData= ScreenCapture.capture(stage,false, region); // 一个按钮,用于启动截屏 var saveBtn:MyButton=new MyButton("save",50,30); saveBtn.x=700; saveBtn.y=150; addChild(saveBtn); saveBtn.addEventListener(MouseEvent.CLICK,save); } private function save(e:MouseEvent):void{ var encoder:JPGEncoder = new JPGEncoder(80); //80是quality var bytes:ByteArray= encoder.encode(bitmapData); var fr:FileReference = new FileReference(); fr.save(bytes, "screen.jpg"); } } } MyButton类 package { import flash.display.* import flash.text.*; import flash.filters.DropShadowFilter; public class MyButton extends SimpleButton { // The text to appear on the button private var _text:String; // Save the width and height of the rectangle private var _width:Number; private var _height:Number; public function MyButton( text:String, width:Number, height:Number ) { // Save the values to use them to create the button states _text = text; _width = width; _height = height; // Create the button states based on width, height, and text value upState = createUpState(); overState = createOverState(); downState = createDownState(); hitTestState = upState; } // Create the display object for the button's up state private function createUpState():Sprite { var sprite:Sprite = new Sprite(); var background:Shape = createdColoredRectangle( 0xcccccc ); var textField:TextField = createTextField( false ); sprite.addChild( background ); sprite.addChild( textField ); return sprite; } // Create the display object for the button's up state private function createOverState():Sprite { var sprite:Sprite = new Sprite(); var background:Shape = createdColoredRectangle( 0xff0000 ); var textField:TextField = createTextField( false ); sprite.addChild( background ); sprite.addChild( textField ); return sprite; } // Create the display object for the button's down state private function createDownState():Sprite { var sprite:Sprite = new Sprite(); var background:Shape = createdColoredRectangle( 0xCCCCCC ); var textField:TextField = createTextField( true ); sprite.addChild( background ); sprite.addChild( textField ); return sprite; } // Create a rounded rectangle with a specific fill color private function createdColoredRectangle( color:uint ):Shape { var rect:Shape = new Shape(); rect.graphics.lineStyle( 1, 0x000000 ); rect.graphics.beginFill( color ); rect.graphics.drawRect( 0, 0, _width, _height); rect.graphics.endFill(); rect.filters = [ new DropShadowFilter( 2 ) ]; return rect; } // Create the text field to display the text of the button private function createTextField( downState:Boolean ):TextField { var textField:TextField = new TextField(); textField.text = _text; textField.width = _width; // Center the text horizontally var format:TextFormat = new TextFormat(); format.align = TextFormatAlign.CENTER; textField.setTextFormat( format ); // Center the text vertically textField.y = ( _height - textField.textHeight ) / 2; textField.y -= 2; // Subtract 2 pixels to adjust for offset // The down state places the text down and to the right // further than the other states if ( downState ) { textField.x += 1; textField.y += 1; } return textField; } } }

网友评论

  • 稀缺资源,谢谢
  • 最后还是没弄成功。。。。
  • 虽然有些问题,但还是谢谢分享
  • 有bug额。。。。不知道为什么
  • 调试时出现错误E:\gkcc\PrintScreen.as,3 行 1172: 找不到定义 aether.utils:ScreenCapture。