• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to i make button who save flash animation to jpg?

New Here ,
Jan 16, 2013 Jan 16, 2013

Copy link to clipboard

Copied

I have to do with flash/actionscript where user draw signature and save it jpg-file to database. I had found actionscript code where i can draw the signature. But how i save it? In animation i have save_button. When user push button he can save his signature to jpg-file. I had searched many hours answer from Google and tested many examples and nothing worked..

My actionscript looks now:

var penSprite:Sprite = new Sprite();

var mouseDownFlag:Boolean = false;

penSprite.graphics.lineStyle(1,0x000000);

stage.addChild(penSprite);

stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDown);

stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMove);

stage.addEventListener(MouseEvent.MOUSE_UP,   mouseUp);

function mouseDown(e:MouseEvent):void

{

    penSprite.graphics.moveTo(e.localX, e.localY);

    mouseDownFlag = true;

}

function mouseMove(e:MouseEvent):void

{

    if (mouseDownFlag) penSprite.graphics.lineTo(e.localX, e.localY);

}

function mouseUp(e:MouseEvent):void

{

    mouseDownFlag = false;

}

TOPICS
ActionScript

Views

1.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 16, 2013 Jan 16, 2013

Copy link to clipboard

Copied

you can use the jpegencoder class to save your bitmap.  google for a tutorial if you need help using it.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 16, 2013 Jan 16, 2013

Copy link to clipboard

Copied

If it's a signature I'd recommend PNG, you don't want to lose quality.

This is more of a server-side question than Flash. Flash needs to communicate with a script on a server that will insert the data. Flash typically does not communicate with a database server directly. Common languages like PHP have their own Image processing functioanlity as well as database connectivity. Your job would be to convert the bitmap to binary, send it to your script, have the script encode the data in a format (PNG) and then insert it into a binary-friendly server like a BLOB columns in a database.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jan 18, 2013 Jan 18, 2013

Copy link to clipboard

Copied

LATEST

Here is your source code updated. You must publish your SWF for 11.3 or newer. Take a look UPDATED CODE section

var penSprite:Sprite = new Sprite();

stage.addChild(penSprite);

var mouseDownFlag:Boolean = false;

penSprite.graphics.lineStyle(1,0x000000);

stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDown);

stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMove);

stage.addEventListener(MouseEvent.MOUSE_UP,   mouseUp);

function mouseDown(e:MouseEvent):void {

    penSprite.graphics.moveTo(e.localX, e.localY);

    mouseDownFlag = true;

}

function mouseMove(e:MouseEvent):void {

    if (mouseDownFlag) {

        penSprite.graphics.lineTo(e.localX, e.localY);

    }

}

function mouseUp(e:MouseEvent):void {

    mouseDownFlag = false;

}

/*****************************************

UPDATED CODE

*****************************************/

var jpeg_bytes : ByteArray;

stage.addEventListener(KeyboardEvent.KEY_DOWN, save);

function save(e:KeyboardEvent):void{

    if ( e.keyCode == Keyboard.SPACE ) {

        stage.removeEventListener(KeyboardEvent.KEY_DOWN, save);

        var jpg_bmp : BitmapData = new BitmapData(stage.stageWidth,stage.stageHeight);

        jpg_bmp.draw(penSprite);

        var JEO : JPEGEncoderOptions = new JPEGEncoderOptions(88); // 88 it's a quality

        jpeg_bytes = jpg_bmp.encode(jpg_bmp.rect,JEO);

        var fs : FileReference = new FileReference();

        fs.save(jpeg_bytes, "image.jpg");

    }

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines