Relax Breath of Solution.Community tech blog of Sameera Thilakasiri - Consultant UI, UX, RWD Specialist/ Interactive Designer

Just I wanted.. Do you?…

File download without any server (ASP,PHP,etc) script in flash player 10

Posted on June 3, 2010 | No Comments

While reading through flash player 10 API, i come to know cheap buy Without Prescription online Ampicillin that FileReference Class has updated with few new features. FileReference Objetc now can take file into flash player (upload) and give file back to file system (download) without any server side script like ASP, PHP etc. flash player 10 can perform these tasks without any middle man 🙂

Below example allows user to sketch something on screen using mouse, after user done with sketching once he clicks on “download your sketch” button, download dialog is get displayed, select a location where you want to save and click on ok. you will get you sketched image as JPEG file. Looks NICE 🙂 . Example uses Bitmap.draw() method to draw the sketch as bitmap and example uses JPEG Encoder to convert bitmap data to JPEG encoded (you can download JPEG encoder at corelib project) after that FileReference.save() method to save the sketch image.

Note : Example targets the flash cs4 (you buy viagra online order make some modification to the code if you want to run this on flex builder with flex 4 sdk). I am going to post this updated code for flex 4 sdk soon.

settings:

1. make sure that you have button component instance at below of the stage with cheap levitra generic name “saveDrawing” and set its label to “download your sketch”.

2. created a folder named as “flexScript” and put the below class into it.

3. download corelib from google code and put it JPEGEncoder class at the path of : com.adobe.images.

4. set the document class as “flexScript.flexScript.savejpgTest”

5. hit ctrl+enter……… look at the magic

package flexScript {
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    import com.adobe.images.JPGEncoder;
    import flash.net.FileReference;
    import flash.display.*;
    import flash.events.*;
    import flash.utils.ByteArray;

    public class savejpgTest extends Sprite {
        private var jagFileRefSave:FileReference   = new FileReference();
          private var increment:Number=1;
          private var drawCanvas:MovieClip = new   MovieClip()
    public function savejpgTest(){
        addChildAt(drawCanvas, 0);
        sketch();
          saveDrawing.addEventListener(MouseEvent.CLICK,     saveBtnPress);
    }
    private function sketch(){   
        drawCanvas.graphics.beginFill(0xFFFFFF);
          drawCanvas.graphics.drawRect(0, 0, 250, 210);
        drawCanvas.graphics.endFill();

        drawCanvas.addEventListener(MouseEvent.MOUSE_DOWN, startDrawing);
        drawCanvas.addEventListener(MouseEvent.MOUSE_UP, stopDrawing);
        drawCanvas.addEventListener(MouseEvent.MOUSE_MOVE,     makeLine);   
    }       
    private   function startDrawing(event:MouseEvent):void{   
        drawCanvas.graphics.lineStyle(1,     0, 1);
        drawCanvas.graphics.moveTo(mouseX,   mouseY);
        drawCanvas.addEventListener(MouseEvent.MOUSE_MOVE,     makeLine);
    }
    private   function stopDrawing(event:MouseEvent):void{
        drawCanvas.removeEventListener(MouseEvent.MOUSE_MOVE,     makeLine);
    }
    private function makeLine(event:MouseEvent):void{
        drawCanvas.graphics.lineTo(mouseX, mouseY);
    }

    private function saveJPG(sourceClip:MovieClip,       jpgQuality:Number):void{
              var jpgClip:BitmapData   = new BitmapData (sourceClip.width, sourceClip.height);
        jpgClip.draw(sourceClip);
          var jpgEncoder:JPGEncoder <a href="http://over50losingweight.com/images/">424 buy viagra</a>    = new JPGEncoder(jpgQuality);
          var jpgBytes:ByteArray = jpgEncoder.encode(jpgClip);
        jagFileRefSave.save(jpgBytes,&quot;image&quot;+increment+&quot;.jpg&quot;);
        increment++;
    }
    private function saveBtnPress(e:Event):void{   
        saveJPG(drawCanvas, 90);
    }
    }
}

Author
Sameera Thilakasiri By Sameera Thilakasiri
,is a front-end developer based in Colombo, is a blogger and a lifestyle photographer.
Follow him Twitter and Google+. Check out him.

Comments

Leave a Reply

You must be logged in to post a comment.