# BitmapData Error..Problem with converting

**URL:** <https://forum.kirupa.com/t/bitmapdata-error-problem-with-converting/284072>\
**Category:** Uncategorized\
**Created:** [March 14, 2009, 4:42pm UTC](https://forum.kirupa.com/t/bitmapdata-error-problem-with-converting/284072 "2009-03-14T16:42:08Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Elementss](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/elementss/32/1698_2.png) [@Elementss](https://forum.kirupa.com/u/Elementss)\
**Post date:** [March 14, 2009, 4:42pm UTC](https://forum.kirupa.com/t/bitmapdata-error-problem-with-converting/284072/1 "2009-03-14T16:42:08Z")

</div>

hi every one.

im trying to create a image downloader…  
im having some problems with converting the MC…

here is my code:

```auto
 
stop();
/*
THIS CODE IF FOR DOWNLOADING sketch_mc THAT IS ON THE MAIN TIMELINE.
IN ADITION TO THAT CODE THERE IS A CODE TO PUT ON THE PAGE (PHP CODE).
/////////////////////////////////////////////////////////////////////
///////////////////////////THE PHP CODE//////////////////////////////
/////////////////////////////////////////////////////////////////////
if (isset($GLOBALS["HTTP_RAW_POST_DATA"]))
{
 // get bytearray
 $jpg = $GLOBALS["HTTP_RAW_POST_DATA"];
 // add headers for download dialog-box
 header('Content-Type: image/jpeg');
 header("Content-Disposition: attachment; filename=".$_GET['name']);
 echo $jpg;
}
/////////////////////////////////////////////////////////////////////
/////////////////////////END OF CODE/////////////////////////////////
/////////////////////////////////////////////////////////////////////
*/
import com.adobe.images.JPGEncoder;
var jpgSource:BitmapData = new BitmapData (sketch_mc.width, sketch_mc.height);
jpgSource.draw(sketch_mc);
var jpgEncoder:JPGEncoder = new JPGEncoder(85);
var jpgStream:ByteArray = jpgEncoder.encode(jpgSource);
dwn_mc.addEventListener(MouseEvent.MOUSE_DOWN,downloadThis);
function downloadThis (arg:MouseEvent){
 
var header:URLRequestHeader = new URLRequestHeader("Content-type", "application/octet-stream");
var jpgURLRequest:URLRequest = new URLRequest("jpg_encoder_download.php?name=sketch.jpg");
jpgURLRequest.requestHeaders.push(header);
jpgURLRequest.method = URLRequestMethod.POST;
jpgURLRequest.data = jpgStream;
navigateToURL(jpgURLRequest, "_blank");
}
/*
///////////////////////////////////////////////////
HERE IS THE START OF IMAGES LOADER TO sketch_mc !!
///////////////////////////////////////////////////
*/
var imageLoader:Loader;
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, loadXML);
loader.load(new URLRequest("IMAGE.xml"));
/////
function loadXML(e:Event):void {
 var xml=new XML(e.target.data);
 var xDoc:XMLDocument = new XMLDocument();
 xDoc.ignoreWhite=true;
 xDoc.parseXML(xml.toXMLString());
 loadImage(xDoc.firstChild.childNodes[0].firstChild);
 trace(xDoc.firstChild.childNodes[0].firstChild);
}
function loadImage([url:String):void](http://www.kirupa.com/forum/String):void) {
 // Set properties on my Loader object
 imageLoader = new Loader();
 imageLoader.load(new URLRequest(url));
 imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
}
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////

function imageLoaded(e:Event):void {
 
 sketch_mc.addChild(imageLoader);
}
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////

```

in addition to thet i post a code on the internet page… PHP…  
the code in the begining…

i get this error when i run the file:

**ArgumentError: Error #2015: Invalid BitmapData.  
at flash.display::BitmapData()  
at DwnImg\_fla::MainTimeline/frame1()**

there is something im missing…

here is the tutorial link:

> **[ActionScript 3 Jpeg Encoder Revealed: Saving Images from Flash - Design Reviver...](https://designreviver.com/tutorials/actionscript-3-jpeg-encoder-revealed-saving-images-from-flash/)**
>
> Some amazing things can be done with images in ActionScript 3. One of these is the ability to encode a display object as a jpeg, and thanks to the JPEG Encoder included in the AS3 Core Library, doing this is actually quite simple. In this article, I...

thanks,  
stas.
