Scaling the source image?

Hi! New to the forum, so apologies if this is in the Tip of The Day or FAQ, I’ve been searching through the site but haven’t had any luck.

I have code that allows users to upload images, which are of any dimension and file size, and have applied that data to a bytearray and a loader class, which is then displayed and saved to the server. The server has a memory size limit per file of 256k. Everything works well unless the image is too big.

So, what I’ve been trying to solve, is figuring out how to change the size of that source image so the server will accept it. I’ve been trying to assign the loader data, or the bytearray, to a Matrix, or a Bitmap, or a BitmapData, figuring one of these can scale the dimensions of the image which will bring down the file size. (To be completely clear: this isn’t movieclip.scaleX – that doesn’t affect the size of the source image)

Now I have found some info via Google, but every possible solution (such as assigning the Loader data to a Bitmap class) responds with “Cannot access a property or method of a null object reference”. I’m certain this is due to my inexperience.

Anyway, if you have any thoughts, I really appreciate it.

Thanks!

var _clickMe:ClickMe = new ClickMe();
var _imageLoader:Loader=new Loader();
var bytes:ByteArray=new ByteArray();
var fileRef:FileReference = new FileReference(); 
var _faceBitmap:Bitmap = new Bitmap();
_clickMe.x=200;
_clickMe.y=200;
addChild(_clickMe);
_clickMe.addEventListener(MouseEvent.CLICK,replaceFace);

function replaceFace(e:Event)
{
    var imagesFilter:FileFilter = new FileFilter("Images", "*.jpg;*.gif;*.png");
    fileRef.addEventListener(Event.SELECT, Editor_fileSelectedCallback); 
    fileRef.browse([imagesFilter]);
}

function Editor_fileSelectedCallback(event:Event):void
{
    fileRef.addEventListener(Event.COMPLETE, Editor_fileLoadedCallback);
    fileRef.load();
}

function Editor_fileLoadedCallback(event:Event):void
{
    bytes=fileRef.data;
    trace("Editor_fileLoadedCallback(event:Event) fileLoaded Complete, " + bytes.length + " bytes.");
    trace("fileRef.size = "+ fileRef.size);
    _imageLoader.loadBytes(bytes);
    if(fileRef.size<=256000)
    {
        trace("image size under limits");
    }
    else
    {
        trace("image too big");
    }
    trace("fileRef.data = "+fileRef.data);
    //var _bitmap:Bitmap = Bitmap(_imageLoader.content);//doesn't error unless you perform any command on it
    addChild(_imageLoader);
    
}