Flash - File saving actionscript

Discussion in 'Programming' started by Website_Playboy, Dec 10, 2010.

  1. #1
    Option 1 = The actionscript should send the file to save.php but i dont have a save.php file and i tried everything to make one grabbing the picture to show but it didint work.

    Option 2 = There is also an option to "save to computer" but i couldnt make it show on the menu. I have change the visibility options to "True" but it didint make difference. This option would be the best if we can do it.

    The entire actionscript is here:
    package ui.dialogs 
    {
        import event.*;
        import flash.display.*;
        import flash.events.*;
        import flash.net.*;
        import flash.utils.*;
        import image.*;
        import image.encoder.*;
        import resource.*;
        import ui.controls.*;
        
        public class SaveImageDialog extends ui.controls.Dialog
        {
            public function SaveImageDialog(arg1:Pixlr, arg2:Boolean=false)
            {
                super(arg1, "rm_save_image", 400, 190, true);
                this.removecanvas = arg2;
                var loc1:*=new ui.controls.Literal(U.RM("rm_format"), true);
                loc1.x = 10;
                loc1.y = 30;
                loc1.width = 50;
                addChild(loc1);
                var loc2:*;
                (loc2 = new ui.controls.Literal(U.RM("rm_name"), true)).x = 10;
                loc2.y = 60;
                loc2.width = 50;
                addChild(loc2);
                var loc3:*;
                if ((loc3 = arg1.canvas.document.name).indexOf(".") != -1) 
                {
                    loc3 = arg1.canvas.document.name.split(".")[0];
                }
                this.tbn = new ui.controls.TextInput(220, 100, loc3);
                this.tbn.x = 61;
                this.tbn.y = 60;
                addChild(this.tbn);
                this.lttype = new ui.controls.Literal(".jpg");
                this.lttype.x = this.tbn.x + this.tbn.width;
                this.lttype.y = 62;
                addChild(this.lttype);
                this.jpgquality = new ui.controls.Slidebar(U.RM("rm_quality"), 0, 100, 100, 80, true);
                this.jpgquality.x = 62;
                this.jpgquality.y = 90;
                addChild(this.jpgquality);
                if (arg1.qs.GetValue("target") != null) 
                {
                    this.savetotarget = new ui.controls.Radiobutton(U.RM("rm_save_back") + " " + (arg1.qs.GetValue("referrer") == null ? U.RM("rm_referrer") : arg1.qs.GetValue("referrer")));
                    this.savetotarget.addEventListener(event.ChangeEvent.CHANGE, this.TargetClick);
                    this.savetotarget.x = 62;
                    this.savetotarget.y = 130;
                    addChild(this.savetotarget);
                    this.savetotarget.Check();
                    this.savetocomputer = new ui.controls.Radiobutton(U.RM("rm_save_to_computer"));
                    this.savetocomputer.addEventListener(event.ChangeEvent.CHANGE, this.TargetClick);
                    this.savetocomputer.x = 62;
                    this.savetocomputer.y = 150;
                    addChild(this.savetocomputer);
                    if (!(arg1.qs.GetValue("locktarget") == null) && arg1.qs.GetValue("locktarget").toLowerCase() == "true") 
                    {
                        this.savetotarget.visible = false;
                        this.savetocomputer.visible = true;
                    }
                }
                this.format = new ui.controls.Dropdown(220, 220);
                this.format.addEventListener(event.SelectEvent.COMMAND, this.FormatChange);
                this.format.AddItem("JPEG (Good for most photos)", "jpg", true);
                this.format.AddItem("PNG (Transparent, full quality)", "png");
                this.format.AddItem("BMP (Large but non-destructive)", "bmp");
                this.format.Bind();
                this.format.x = 61;
                this.format.y = 30;
                addChild(this.format);
                var loc4:*;
                cancel.x = loc4 = 319;
                ok.x = loc4;
                ok.y = 25;
                cancel.y = 54;
                return;
            }
    
            internal function SaveJpg(arg1:flash.display.BitmapData):void
            {
                var loc1:*=new image.encoder.JPGEncoder(this.jpgquality.value);
                this.Save("jpg", this.tbn.text + ".jpg", loc1.encode(arg1));
                return;
            }
    
            internal function SavePng(arg1:flash.display.BitmapData):void
            {
                this.Save("png", this.tbn.text + ".png", image.encoder.PNGEncoder.encode(arg1));
                return;
            }
    
            internal function StoreError(arg1:flash.events.Event):void
            {
                trace("error");
                Close();
                new ui.controls.AlertDialog(p, U.RM("rm_error_occurred"));
                return;
            }
    
            internal function TargetClick(arg1:event.ChangeEvent):void
            {
                this.savetotarget.Check(false);
                this.savetocomputer.Check(true);
                (arg1.target as ui.controls.Radiobutton).Check();
                return;
            }
    
            internal function StoreComplete(arg1:flash.events.Event):void
            {
                var loc1:*=undefined;
                var loc2:*=null;
                trace("store");
                if (arg1.target.data != "") 
                {
                    loc1 = String(arg1.target.data);
                    if (loc1.indexOf("ERR") == -1) 
                    {
                        loc2 = p.qs.GetValue("target");
                        if (loc2.indexOf("?") != -1) 
                        {
                            loc2 = loc2 + "&";
                        }
                        else 
                        {
                            loc2 = loc2 + "?";
                        }
                        loc2 = loc2 + "image=" + encodeURI(p.rooturl + "/_temp/" + loc1);
                        loc2 = loc2 + "&type=" + encodeURI(this.format.value);
                        loc2 = loc2 + "&state=" + encodeURI(p.canvas.document.external ? "fetched" : "new");
                        loc2 = loc2 + "&title=" + encodeURI(this.tbn.text);
                        if (p.qs.GetValue("redirect") == null) 
                        {
                            flash.net.navigateToURL(new flash.net.URLRequest(loc2), "_self");
                        }
                        else 
                        {
                            flash.net.sendToURL(new flash.net.URLRequest(loc2));
                            flash.net.navigateToURL(new flash.net.URLRequest(p.qs.GetValue("redirect")), "_self");
                        }
                    }
                    else 
                    {
                        this.StoreError(null);
                    }
                    Close();
                }
                return;
            }
    
            public override function OKClick(arg1:flash.events.MouseEvent):void
            {
                if (this.tbn.text == "") 
                {
                    this.tbn.text = U.RM("rm_untitled");
                }
                var loc1:*=this.format.value;
                switch (loc1) 
                {
                    case "jpg":
                    {
                        p.canvas.UpdateAfterEdit(-1, 16777215);
                        this.SaveJpg(p.canvas.screenshot);
                        break;
                    }
                    case "png":
                    {
                        p.canvas.UpdateAfterEdit();
                        this.SavePng(p.canvas.screenshot);
                        break;
                    }
                    case "bmp":
                    {
                        p.canvas.UpdateAfterEdit();
                        this.SaveBmp(p.canvas.screenshot);
                        break;
                    }
                }
                if (this.removecanvas) 
                {
                    p.RemoveCanvas();
                }
                return;
            }
    
            internal function Save(arg1:String, arg2:String, arg3:flash.utils.ByteArray):void
            {
                var loc1:*=null;
                var loc2:*=null;
                var loc3:*=null;
                var loc4:*=null;
                trace("save");
                if ((this.savetotarget == null || this.savetotarget.checked) && !(p.qs.GetValue("target") == null)) 
                {
                    if (p.qs.GetValue("method") == null || p.qs.GetValue("method").toLowerCase() == "get") 
                    {
                        (loc1 = new flash.net.URLLoader()).addEventListener(flash.events.Event.COMPLETE, this.StoreComplete);
                        loc1.addEventListener(flash.events.IOErrorEvent.IO_ERROR, this.StoreError);
                        loc1.dataFormat = flash.net.URLLoaderDataFormat.BINARY;
                        loc1.load(image.Misc.GenerateRequest(p.rooturl + "/store.php?type=" + arg1, arg3, arg2, arg1, "store"));
                    }
                    else if (!(p.qs.GetValue("credentials") == null) && p.qs.GetValue("credentials").toLowerCase() == "true") 
                    {
                        loc2 = p.qs.GetValue("target");
                        if (p.qs.GetValue("redirect") == null) 
                        {
                            flash.net.navigateToURL(image.Misc.GenerateRequest(loc2, arg3, arg2, arg1, p.canvas.document.external ? "fetched" : "new"), "_self");
                        }
                        else 
                        {
                            flash.net.sendToURL(image.Misc.GenerateRequest(loc2, arg3, arg2, arg1, p.canvas.document.external ? "fetched" : "new"));
                            flash.net.navigateToURL(new flash.net.URLRequest(p.qs.GetValue("redirect")), "_self");
                        }
                    }
                    else 
                    {
                        loc2 = (loc2 = (loc2 = p.rooturl + "/forward.php") + "?") + "&url=" + encodeURI(p.qs.GetValue("target"));
                        if (p.qs.GetValue("redirect") == null) 
                        {
                            flash.net.navigateToURL(image.Misc.GenerateRequest(loc2, arg3, arg2, arg1, p.canvas.document.external ? "fetched" : "new"), "_self");
                        }
                        else 
                        {
                            flash.net.sendToURL(image.Misc.GenerateRequest(loc2, arg3, arg2, arg1, p.canvas.document.external ? "fetched" : "new"));
                            flash.net.navigateToURL(new flash.net.URLRequest(p.qs.GetValue("redirect")), "_self");
                        }
                    }
                }
                else 
                {
                    loc3 = new flash.net.URLRequestHeader("Content-type", "application/x-www-form-urlencoded");
                    (loc4 = new flash.net.URLRequest(p.rooturl + "/save.php?name=" + arg2 + "&type=" + arg1)).requestHeaders.push(loc3);
                    loc4.method = flash.net.URLRequestMethod.POST;
                    loc4.data = arg3;
                    flash.net.navigateToURL(loc4, "_self");
                    Close();
                }
                return;
            }
    
            internal function FormatChange(arg1:event.SelectEvent):void
            {
                this.jpgquality.visible = false;
                var loc1:*=arg1.val as String;
                switch (loc1) 
                {
                    case "jpg":
                    {
                        this.jpgquality.visible = true;
                        this.lttype.text = ".jpg";
                        break;
                    }
                    case "png":
                    {
                        this.lttype.text = ".png";
                        break;
                    }
                    case "bmp":
                    {
                        this.lttype.text = ".bmp";
                        break;
                    }
                }
                return;
            }
    
            internal function SaveBmp(arg1:flash.display.BitmapData):void
            {
                var loc1:*=new image.encoder.BMPEncoder();
                this.Save("bmp", this.tbn.text + ".bmp", loc1.encode(arg1));
                return;
            }
    
            var tbn:ui.controls.TextInput;
    
            var lttype:ui.controls.Literal;
    
            internal var savetotarget:ui.controls.Radiobutton;
    
            internal var savetocomputer:ui.controls.Radiobutton;
    
            var removecanvas:Boolean;
    
            internal var uploadURL:flash.net.URLRequest;
    
            internal var format:ui.controls.Dropdown;
    
            internal var ld:ui.controls.LoadDialog;
    
            internal var file:flash.net.FileReference;
    
            var jpgquality:ui.controls.Slidebar;
        }
    }
    
    Code (markup):
    Please help me out about it. I have spend the last 10 hours on it without any progress.
     
    Website_Playboy, Dec 10, 2010 IP