/* * * PNG2SWF JSFL v1.0 * by Mr.doob * */ alert("Welcome to Mr.doob's PNG2SWF. How are you?"); loadPNG(); function loadPNG() { 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 doc = fl.createDocument(); doc.backgroundColor = '#00FF00'; doc.importFile(pngURI); var bmp_lib = fl.getDocumentDOM().library.items[0]; bmp_lib.quality = Number(jpeg_quality); 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"; if (!FLfile.exists(swfURI)) { doc.exportSWF(swfURI, true ); } else { alert("!MEEEK! There is a .swf already created"); } doc.close(false); alert("PNG: " + FLfile.getSize(pngURI) + ", SWF: " + FLfile.getSize(swfURI) + " Compression: " + Math.floor((FLfile.getSize(swfURI) / FLfile.getSize(pngURI))*100) + " %"); }