/* * * PNG2SWF JSFL v1.2 * by Mr.doob * */ script(); function script() { var pngURI = fl.browseForFileURL("open","Select the PNG:",false); if (pngURI == null) { return; } if (pngURI.substr(pngURI.length-4) != ".png") { alert("!MEEK! Selected file is not a .png"); return; } var jpeg_quality = prompt("JPEG Quality?", "85"); var allowSmoothing = confirm("Bitmap smoothing?"); var securityAllowDomain = confirm("Add Security.allowDomain(\"*\") code?"); var doc = fl.createDocument(); doc.backgroundColor = '#00FF00'; doc.importFile(pngURI); var bmp_lib = fl.getDocumentDOM().library.items[0]; bmp_lib.quality = Number(jpeg_quality); if (allowSmoothing) bmp_lib.allowSmoothing = true; if (securityAllowDomain) fl.getDocumentDOM().getTimeline().layers[0].frames[0].actionScript = 'Security.allowDomain("*");'; var bmp_tl = fl.getDocumentDOM().getTimeline().layers[0].frames[0].elements[0]; doc.width = Math.floor(bmp_tl.width); doc.height = Math.floor(bmp_tl.height); var swfURI = pngURI.substr(0,pngURI.lastIndexOf(".")+1)+"swf"; doc.exportSWF(swfURI, true ); doc.close(false); fl.trace("PNG: " + FLfile.getSize(pngURI) + ", SWF: " + FLfile.getSize(swfURI) + " - Compression: " + Math.floor((FLfile.getSize(swfURI) / FLfile.getSize(pngURI))*100) + " %"); }