Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package
- {
- import adobe.utils.CustomActions;
- import com.adobe.images.JPGEncoder;
- import com.adobe.images.PNGEncoder;
- import flash.display.DisplayObject;
- import flash.display.Sprite;
- import flash.events.Event;
- import flash.filters.DropShadowFilter;
- import flash.utils.ByteArray;
- import flash.events.IOErrorEvent;
- import flash.net.FileReference;
- import flash.net.FileFilter;
- import flash.display.Loader;
- import flash.display.LoaderInfo;
- import flash.text.TextField;
- import sliz.miniui.Button;
- import sliz.miniui.Label;
- import sliz.miniui.Silder;
- import sliz.miniui.skin.ButtonCoreSkin;
- /**
- * ...
- * @author @bitetti
- */
- [Frame(factoryClass="Preloader")]
- public class Main extends Sprite
- {
- // ui
- //private var loadBot:Button;
- //private var saveBot:Button;
- //private var zoomBot:Silder;
- //private var brilhoBot:Silder;
- private var file:FileReference;
- // tela
- private var ubunted:Ubunted;
- public function Main():void
- {
- if (stage) init();
- else addEventListener(Event.ADDED_TO_STAGE, init);
- }
- private function init(e:Event = null):void
- {
- removeEventListener(Event.ADDED_TO_STAGE, init);
- // entry point
- file = new FileReference;
- file.addEventListener(Event.SELECT, selectHandler);
- addChild( ubunted = new Ubunted );
- addChild( new Button("Carregar", 4, 154, null, preparaLoad ) );
- addChild( new Button("JPEG", 70, 154, null, preparaSalvar ) );
- addChild( new Button("PNG", 118, 154, null, preparaSalvar2 ) );
- addChild( new Silder(148, 142, null, "", null, 100, 270, silderFunc ));
- Silder(getChildAt(numChildren - 1)).value = 0.5;
- addChild( new Silder(168, 142, null, "", null, 100, 270, silder2Func ));
- Silder(getChildAt(numChildren - 1)).value = 0.4;
- /*addChild( new Label("Contraste", null, 4, 174) );
- addChild( new Silder(64, 180, null, "", null, 100, 0, silder7Func) );*/
- addChild( new Label("Desfoque", null, 4, 174) );
- addChild( new Silder(64, 180, null, "", null, 100, 0, silder3Func) );
- addChild( new Label("Fish Eye", null, 4, 194) );
- addChild( new Silder(64, 200, null, "", null, 100, 0, silder4Func) );
- addChild( new Silder(64, 220, null, "", null, 100, 0, silder5Func) );
- Silder(getChildAt(numChildren - 1)).value = 0.5;
- addChild( new Silder(64, 240, null, "", null, 100, 0, silder6Func) );
- Silder(getChildAt(numChildren - 1)).value = 0.5;
- addChild( new Label("@powered by", null, 120, 256 ) );
- getChildAt(numChildren - 1).scaleX = getChildAt(numChildren - 1).scaleY = 0.7;
- TextField( getChildAt(numChildren - 1) ).htmlText = "<font color=\"#4040ff\"><a href=\"https://github.com/marcosbitetti/Parallax-Scroll-Web-Objects\" target=\"_new\">@powered by</a></font>";
- //zoomBot.value = 0.5;
- //brilhoBot.value = 0.4;
- }
- private function silderFunc( e:Event ):void
- {
- var sl:Silder = e.target as Silder;
- ubunted.scale = 2*sl.value;
- }
- private function silder2Func( e:Event ):void
- {
- var sl:Silder = e.target as Silder;
- ubunted.brilho = sl.value;
- }
- private function silder3Func( e:Event ):void
- {
- var sl:Silder = e.target as Silder;
- ubunted.blur = sl.value;
- }
- private function silder4Func( e:Event ):void
- {
- var sl:Silder = e.target as Silder;
- ubunted.fish_rad = sl.value;
- }
- private function silder5Func( e:Event ):void
- {
- var sl:Silder = e.target as Silder;
- ubunted.fish_x = sl.value;
- }
- private function silder6Func( e:Event ):void
- {
- var sl:Silder = e.target as Silder;
- ubunted.fish_y = sl.value;
- }
- private function silder7Func( e:Event ):void
- {
- var sl:Silder = e.target as Silder;
- ubunted.nitidez = sl.value;
- }
- private function addMessage(msg:String):void
- {
- removeMessage();
- var shp:Sprite = new Sprite;
- shp.name = "mensagem";
- shp.graphics.clear();
- shp.graphics.beginFill(0xffffff, 0.83);
- shp.graphics.lineStyle(1, 0x303030, 0.5);
- shp.graphics.drawRoundRect(0, 0, 120, 100, 12, 12);
- shp.graphics.endFill();
- shp.filters = [ new DropShadowFilter(2, 2, 0x000000, 0.8, 8, 8, 1, 3, false, false, false) ];
- shp.x = root.width / 2 - shp.width / 2;
- shp.y = root.height / 2 - shp.height / 2;
- var tx:TextField = new TextField;
- tx.wordWrap = tx.multiline = true;
- tx.width = 100;
- tx.height = 90;
- tx.x = 10;
- tx.y = 5;
- tx.text = msg;
- shp.addChild(tx);
- addChild(shp);
- }
- private function removeMessage():void
- {
- var d:DisplayObject = getChildByName("mensagem");
- if (d) removeChild(d);
- d = null;
- }
- private function preparaSalvar(e:Event):void
- {
- var finalData:ByteArray;
- for (var i:int = 95; i > 50; i++)
- {
- addMessage("Preparando optimização...\nTeste com " + i.toString());
- var encoder:JPGEncoder = new JPGEncoder(85);
- var encodedImage:ByteArray = encoder.encode(ubunted.getCanvas() );
- if (encodedImage.bytesAvailable < 9700)
- {
- finalData = encodedImage;
- break;
- }
- }
- if (finalData == null) finalData = encodedImage;
- var saveFile:FileReference = new FileReference();
- saveFile.addEventListener(Event.COMPLETE, saveCompleteHandler);
- saveFile.addEventListener(IOErrorEvent.IO_ERROR, saveIOErrorHandler);
- saveFile.save(finalData, "avatar.jpg");
- removeMessage();
- }
- private function preparaSalvar2(e:Event):void
- {
- var encodedImage:ByteArray = PNGEncoder.encode(ubunted.getCanvas() );
- var saveFile:FileReference = new FileReference();
- saveFile.addEventListener(Event.COMPLETE, saveCompleteHandler);
- saveFile.addEventListener(IOErrorEvent.IO_ERROR, saveIOErrorHandler);
- saveFile.save(encodedImage, "avatar.png");
- removeMessage();
- }
- private function saveCompleteHandler(e:Event):void
- {
- }
- private function saveIOErrorHandler(e:IOErrorEvent):void
- {
- }
- private function preparaLoad(e:Event):void
- {
- file.browse([new FileFilter("Images: (*.jpeg, *.jpg, *.gif, *.png)", "*.jpeg; *.jpg; *.gif; *.png")]);
- }
- private function selectHandler( e:Event ):void
- {
- file.addEventListener(Event.COMPLETE, loadHandler);
- file.load();
- }
- private function loadHandler( e:Event ):void
- {
- file.removeEventListener(Event.COMPLETE, loadHandler);
- var loader:Loader = new Loader();
- loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadBytesHandler);
- loader.loadBytes(file.data);
- }
- private function loadBytesHandler( e:Event ):void
- {
- var loaderInfo:LoaderInfo = (e.target as LoaderInfo);
- loaderInfo.removeEventListener(Event.COMPLETE, loadBytesHandler);
- ubunted.setupImage(loaderInfo.content);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment