public class SaveByteArray
The SaveByteArray class allows to save high quality images with unique names in a folder on the server. This class requires a server side script and the Adobe image encoder classes. Use the constructor new SaveByteArray() to create an instance of the class and add parameters as desired.
Public Methods
Method Defined By
Creates a new instance of the SaveByteArray class.
initLoader(loadFinished:Function, myURL:String, mClip:DisplayObjectContainer,qual:int=80._image:String="jpg"._width:int=1000._height:int=1000._time:int=1000.myTarget:Object=null.aNum:Object=null)
This function will trigger to create a new bitmap and save it on the server in jpg or png format.
This function will stop the counting to wait for saving the image.
Event Defined By
All inherited events of the Sprite class.
Constructor Detail
SaveByteArray ()  Constructor
public function SaveByteArray()
Intializes a new SaveByteArray instance.
Method Detail

initLoader()  method
public function initLoader(loadFinished:Function, myURL:String, mClip:DisplayObjectContainer, qual:int=80, _image:String="jpg", _width:int=1000, _height:int=1000, _time:int=1000, myTarget:Object=null, aNum:Object=null):void

This function will trigger to create a new bitmap and save it on the server in jpg or png format.


  • loadFinished:Function ____ Specifies the listener function when the image is saved.
  • myURL:String ____ Specifies the url for the php file. Add a name at the end of the url and if required a folder name. A typical url looks like this: "".
  • mClip:DisplayObjectContainer ____ Specifies the holder for the image to be used as a template to save.
  • qual:int=80 ____ Specifies the quality of the image to be saved. Default is 80 and maximum value is 100.
  • _image:String="jpg" ____ Specifies the type of image to be created. Default is jpg and the other possibility is png.
  • _width:int=1000 ____ Specifies the width of the new image. Default is 1000 pixel.
  • _height:int=1000 ____ Specifies the height of the new image. Default is 1000 pixel.
  • _time:int=1000 ____ Specifies the time interval of the new image. Default is 1000 msec.
  • myTarget:Object=null ____ Specifies a textfield to count the waiting time. Default is null.
  • aNum:Object=null ____ Specifies any kind of parameter to transfer to the listener function. Default is null.

stopTimer()  method
public function stopTimer():void

This function will stop the counting to wait for saving the image.

Create a new fla file and name it SaveBytearrayexample.fla. Place the fla in the same folder as the biz folder. Put a UILoader component (imgHolder), two Button components (submitBut, showImg) and one TLFTextField instance (waitCounter) on the stage. Place 4 button components and name them A0, A1, A2, A3. Then create an Actionscript file, name it and place this script.

	import flash.display.Sprite;
	import fl.containers.UILoader;
	import fl.controls.Button;
	import biz.flashscript.utils.SaveByteArray;
	import fl.text.TLFTextField;
	import flashx.textLayout.formats.TextLayoutFormat;
	import flashx.textLayout.elements.TextFlow;

	public class SaveBytearrayexample extends Sprite
		public var imgHolder:UILoader;
		public var submitBut:Button;
		public var waitCounter:TLFTextField;
		public var showImg:Button;
		private var _widthSetter:TLFTextField;
		private var _heightSetter:TLFTextField;
		private var imgLoader:SaveByteArray;
		public var A0:Button;
		public var A1:Button;
		public var A2:Button;
		public var A3:Button;

		public function SaveBytearrayexample ():void
			_widthSetter = new TLFTextField();
			_widthSetter.x = 88;
			_widthSetter.y = 150;
			_widthSetter.restrict = "0-9";
			_widthSetter.text = "500";
			_widthSetter.width = 80;
			_widthSetter.height = 25;
			_widthSetter.background = true;
			_widthSetter.backgroundColor = 0xCCCCCC;
			_widthSetter.type = "input";
			addChild (_widthSetter);
			_heightSetter = new TLFTextField();
			_heightSetter.text = "500";
			_heightSetter.x = 88;
			_heightSetter.y = 180;
			_heightSetter.width = 80;
			_heightSetter.height = 25;
			_heightSetter.background = true;
			_heightSetter.backgroundColor = 0xCCCCCC;
			_heightSetter.type = "input";
			addChild (_heightSetter);
			var myFormat:TextLayoutFormat = new TextLayoutFormat();
			myFormat.color = 0x336633;
			myFormat.fontFamily = "Arial, Helvetica, _sans";
			myFormat.fontSize = 18;
			myFormat.textAlign = "center";
			var myTextFlow1:TextFlow = _widthSetter.textFlow;
			myTextFlow1.hostFormat = myFormat;
			myTextFlow1.flowComposer.updateAllControllers ();
			var myTextFlow2:TextFlow = _heightSetter.textFlow;
			myTextFlow2.hostFormat = myFormat;
			myTextFlow2.flowComposer.updateAllControllers ();
			A0.label = "image 1";
			A0.addEventListener (MouseEvent.CLICK, selectImage);
			A1.label = "image 2";
			A1.addEventListener (MouseEvent.CLICK, selectImage);
			A2.label = "image 3";
			A2.addEventListener (MouseEvent.CLICK, selectImage);
			A3.label = "image 4";
			A3.addEventListener (MouseEvent.CLICK, selectImage);
			submitBut.label = "Save Image";
			showImg.label = "Show image";
			showImg.visible = false;
			showImg.addEventListener (MouseEvent.CLICK, showImage);
			submitBut.addEventListener (MouseEvent.CLICK, clickHandler);
		private function selectImage (ev:Event):void
			imgHolder.source = """.jpg";
		private function clickHandler (ev:Event):void
			waitCounter.text = "Saving starts in a second...";
			imgLoader = new SaveByteArray();
			var _url:String = "";
			var _width:int = int(_widthSetter.text);
			var _height:int = int(_heightSetter.text);
			imgLoader.initLoader (imageUrlLoaderComplete,_url,imgHolder,100,"jpg",_width,_height,1000,waitCounter);
		private function imageUrlLoaderComplete (evt:Event=null,a:Object=null):void
			if (evt != null)
				var _result:String = unescape(;
			if (a != null)
				_result = String(a);
			imgLoader.stopTimer ();
			waitCounter.htmlText = _result;
			if (_result == "File is not correct!")
				navigateToURL (new URLRequest(""));
				showImg.visible = true;
		private function showImage (ev:Event):void
			navigateToURL (new URLRequest(""));
The following php script (imageSaver.php) is located on the server as specified by the URL.

$absolutepath = dirname(__FILE__);
if ( isset ( $GLOBALS["HTTP_RAW_POST_DATA"] )) 
	$filename = $_GET['name'];
	$folder = $_GET['folder'];
	$counter = $_GET['count'];
	if(!file_exists ($folder))
		mkdir($folder, 0777);
		if (!chmod("$folder",0777))
			fail("The permissions failed to set to 0777.");
		fail("Could not open file!.");
		fail("Could not write to file!.");
	fail("Could not place the file");
function success($counter)
	$counter = $counter+1;
	echo "myResult=$counter";
function fail($errmess)
	echo "myResult=".$errmess;