Posts Tagged ‘locally’

Reusing BitmapData for Multiple Bitmap/Image Objects

Thursday, June 6th, 2013

I was working with Bitmap and BitmapData objects quite a lot recently.

Noticed that it is better to reuse the BitmapData objects for each new Bitmap object that is created, where the underlying pixels will be the same. They can then be manipulated as required separately, but without having multiple instances of the complex BitmapData object.

A code example I was using to check this out, as well as for loading the sample image locally in Air, is given below:

<mx:WindowedApplication xmlns:mx="" layout="absolute" 
						creationComplete="creationCompleteHandler(event)" >
			import mx.controls.Image;
			import mx.core.UIComponent;
			private var myTimer:Timer;
			private var myBitmapData:BitmapData;
			protected function creationCompleteHandler(event:FlexEvent):void
				var urlString:String = "file:///C:/assets/images/client_logo.png";
				var req:URLRequest = new URLRequest(urlString);
				var ldr:Loader = new Loader();
				ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, fileLoadComplete);
				ldr.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onIOError);				
			private function onIOError(event:IOErrorEvent):void{
			private function fileLoadComplete(event:Event):void
				var ldr:Loader = Loader(;
				var bitmap:Bitmap = Bitmap(ldr.content);
				myBitmapData = bitmap.bitmapData;
				displayImage1.source = new Bitmap(myBitmapData);		
				displayImage2.source = new Bitmap(myBitmapData);
	<mx:Image id="displayImage1"/>
	<mx:Image id="displayImage2" y="0" x="50"/>


Flash Player 10.1 and AIR 2.5 the reuse of BitmapData among many instances of Bitmap objects is now done automatically, for improved performance.

Flex: testing/running php proxy locally

Friday, October 15th, 2010

When accessing URL’s through HttpServices from a remote domain, it often works fine on the local system but fails to connect when the swf is uploaded to the web (google searh ‘flex crossdomain.xml proxy’).

A common way around this is to place a PHP file on your web server that acts as a go-between for the remote site and the swf (an example discussed on Dennis Jaamaan’s site, with proxy code).

This article explains how to setup a local PHP server, and test your PHP proxy locally through Flex Builder 3

1. Download a PHP server:

2. Install it, leaving whatever default settings it suggests.

3. Click the WampServer taskbar icon, and go to PHP/PHP_extensions/ and click php_curl (need to enable this to use the example below). Then click Start All Services & Put Online.

4. Create a php file named flexProxy.php and put in the code below:

< ?php
$ch = curl_init();
$timeout = 30;
$userAgent = $_SERVER['HTTP_USER_AGENT'];

$url = $_REQUEST['url'];
$place = $_REQUEST['place'];

$fullGoogleWeatherPath = $url . $place;

curl_setopt($ch, CURLOPT_URL,$fullGoogleWeatherPath);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);

$response = curl_exec($ch);

if (curl_errno($ch)) {
    echo curl_error($ch);
} else {
    echo $response;

5. Save this file and put it in the localhost directory: C:\wamp\www\

Read the rest of this article…………….