0

I'm trying to make a character creator application using flash actionscript 2. I'm quite done with the character's moveable parts, however my main concern is on how to save the image as jpeg/png. I tried to search for tutorials on the net but most of it would suggest using php.

Is there any way that i can save an image without the use of php? I would like to save my characters image using a button, and save it directly to my pc.

1
  • Your first mistake was coding it in AS2. Why?? That too in Flash CS4, which is more AS3 than AS2?? You really can't do it in AS2, so you're going to have to port your code to AS3 or not do it in Flash Commented Feb 7, 2012 at 15:33

2 Answers 2

1

You can create a container in AS3 and load your AS2 application into it. So you can use AS3 code in that container to save the image into your PC. Let me know if you need help regarding this.

You need to deploy both the files in your release. AS3 swf will be your primary swf and AS2 swf will be loaded into it.

// code

package

{

import asfiles.encoding.*;

import flash.display.*;
import flash.events.*;
import flash.geom.*;
import flash.net.*;
import flash.utils.ByteArray;

public class AS3Container extends MovieClip
{

    public var myRequest:URLRequest;
    public var l:Loader;

    public function AS3Container()
    {   
       myRequest = new URLRequest("scene.swf"); // load your AS2 swf
       l = new Loader();
       l.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
       l.load(myRequest);

       saveButton.enabled = false;         

       saveButton.addEventListener(MouseEvent.CLICK, saveHandler);
    }// end function

    public function onComplete(event:Event)
    {
       this.addChild(l);
       l.width = stage.width;
       l.height = stage.height;
       saveButton.enabled = true;

    }// end function

    public function saveHandler(event:MouseEvent) : void
    {                     
        saveImage(l,"myImg.jpg");   

    }// end function

     public function saveImage(image:Loader, imageName:String) {

            var _rect:Rectangle = null;
            var _matrix:Matrix = null;
            trace(image.x+","+image.y);             
            _rect = new Rectangle(image.width/2, image.height/2, image.width, image.height);                
            var jpgSource:BitmapData = new BitmapData(image.width, image.height);
            jpgSource.draw(image, _matrix);
            jpgEncoder = new JPEGEncoder(100);
            var jpgStream:ByteArray = jpgEncoder.encode(jpgSource);               
            var file:FileReference = new FileReference();
            file.save( jpgStream, imageName );

    }

}

}

The approach used in this link will help you to save using AS3 and PHP. http://subashflash.blogspot.in/2013/10/save-image-from-as2-project-using-as3.html.

Sign up to request clarification or add additional context in comments.

1 Comment

Not working anymore, I uploaded the script but not showing any save button for the action ! farshadghazanfari.com/demo/saveimg/save.html
0

Not possible using AS2. In order to save an image you would need to write it to a format that allows null bytes (i.e. octets of bits which are all unset). Your best approach to a byte sequence is a string, but null-byte would terminate it.

1 Comment

Yeah, I think it must be a mistake coding it in AS2. I will code it as3, do you have any tutorial or links that could somehow answer this question? Change the question already.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.