Display of saved image

We now want to display the saved image when we come back. We add a button to display the image and give the button some function.

var mc2:ShowBut = new ShowBut ();
mc2.x = this.stage.width/2 - mc2.width/2;
mc2.y = 300;
this.buttonMode = true;
this.addChild (mc2);
mc2.addEventListener (MouseEvent.MOUSE_DOWN, showHandler)

We call the SharedObject and ask if it contains data. If so we create a BitmapData object and fill it using the ByteArray data, which are stored in the SharedObject. We use setPixels to do this. Then we create a Bitmap and add this to the stage.

function showHandler (event:MouseEvent):void
{
	var my_so:SharedObject = SharedObject.getLocal ("kookie");
	if (my_so.data.image != null)
	{
		var myBitmapData_2:BitmapData = new BitmapData (canvas.width, canvas.height, false, 0x00FFFFFF);
		var rect_2:Rectangle = new Rectangle(0, 0, canvas.width, canvas.height);
		myBitmapData_2.setPixels(rect_2, my_so.data.image);
		var bm:Bitmap = new Bitmap(myBitmapData_2);
		bm.name = "bm";
		this.addChild(bm);
		bm.x = this.stage.width/2 - bm.width/2;
		bm.y = this.stage.height/2 - bm.height/2;
	}
}
		

previous