ActionScript 3

//You need this, and the file saving only works in AIR// https://github.com/mikechambers/as3corelib/blob/master/src/com/adobe/images/PNGEncoder.asfunction saveImage(){varcopyData:BitmapData=newBitmapData(stage.stageWidth,stage.stageHeight);copyData.draw(stage);//var copyBitmap:Bitmap = new Bitmap(copyData);//addChild(copyBitmap);//trace(copyData);//copyBitmap.x = 50;//copyBitmap.y = 50;//create a new instance of the encoder varpngenc:PNGEncoder=newPNGEncoder();//trace(pngenc);//encode the bitmapdata object and keep the encoded ByteArrayvarimgByteArray:ByteArray=pngenc.encode(copyData);varfl:File=File.desktopDirectory.resolvePath("snapshot.png");//Now we can save the ByteArray to a file using FileStream class: //Use a FileStream to save the bytearray as bytes to the new filevarfs:FileStream=newFileStream();try{fs.open(fl,FileMode.WRITE);fs.writeBytes(imgByteArray);fs.close();trace("success");}catch(e:Error){trace("error: "+e.message);}}

ActionScript 3

packageapp{importflash.display.*;importflash.events.*;importflash.desktop.NativeApplication;importflash.system.Capabilities;publicclassWelcomeScreenextendsMovieClip{//Seems to be used in a lot of examples privatevarwin:NativeWindow;privatevarclose_btn:Close_btn;privatevarresizeAndCenter_btn:ResizeAndCenter_btn;publicfunction WelcomeScreen(){trace("Welcome Screen");addEventListener(Event.ADDED_TO_STAGE,init);}privatefunction init(e:Event){removeEventListener(Event.ADDED_TO_STAGE,init);stage.align=StageAlign.TOP_LEFT;stage.scaleMode=StageScaleMode.NO_SCALE;win=stage.nativeWindow;//ConvenienceaddGraphics();}privatefunction addGraphics(){//Createclose_btn=newClose_btn();resizeAndCenter_btn=newResizeAndCenter_btn();//Postitionclose_btn.x=1;close_btn.y=1;resizeAndCenter_btn.x=1;resizeAndCenter_btn.y=32;setButton(close_btn);setButton(resizeAndCenter_btn);}privatefunction onClick(me:MouseEvent){switch(me.target){caseclose_btn:trace("close_btn");NativeApplication.nativeApplication.exit();break;caseresizeAndCenter_btn:trace("resizeAndCenter_btn");resizeWindow();centerWindow();break;default:trace("none");}}privatefunction setButton(mc:MovieClip){mc.addEventListener(MouseEvent.CLICK,onClick);mc.mouseChildren=false;mc.buttonMode=true;addChild(mc);}privatefunction resizeWindow(){win.x=600;win.y=300;win.width=400;win.height=200;}privatefunction centerWindow(){win.x=(Capabilities.screenResolutionX-win.width)/2;win.y=(Capabilities.screenResolutionY-win.height)/2;}}}

ActionScript 3

privatevarmonitor:URLMonitor;// This is just ane example of a function called after application creation completeprivatefunction handle_creationComplete():void{monitor=newURLMonitor(newURLRequest("http://www.someaddress to check against"));monitor.addEventListener(StatusEvent.STATUS,handle_network_status);monitor.start();}privatefunction handle_network_status(event:StatusEvent):void{trace(monitor.available);}