Here’s the working code. Hope this is what you wanted: http://rostok.3e.pl/download/MagicMirror.zip
/**
* MagicMirror creates two entangled entities at different layers.
* The one at top renders everything that is below the one at the bottom.
*
* Master is at the bottom because it is processed first
* @author rostok
*/
public class MagicMirror extends Entity
{
public var slave:MagicMirror = null;
public var master:MagicMirror = null;
public var saved:BitmapData = null;
public var topLayer:int;
public var isMaster:Boolean;
public function MagicMirror(x:Number=0, y:Number=0, w:Number=0, h:Number=0, layer:int=0, topLayer:int=0, isMaster:Boolean=true, g:Graphic = null)
{
// store position, dimensions and layers, and is it master
this.layer = isMaster ? layer : topLayer;
this.width = w;
this.height = h;
this.topLayer = topLayer;
this.isMaster = isMaster;
this.x = x;
this.y = y;
if (g) this.graphic = g;
}
override public function added():void
{
super.added();
if (isMaster)
{
slave = new MagicMirror(x, y, width, height, layer, topLayer, false);
slave.master = this;
world.add( slave );
}
}
override public function render():void
{
//super.render();
//return;
if (isMaster)
{
// copy position and dimensions to slave
if (slave)
{
slave.x = x;
slave.y = y;
slave.width = width;
slave.width = height;
}
// store part of the buffer
saved = new BitmapData(width, height, true, 0);
// copy part of the screen
if (graphic && graphic is Image)
saved.copyPixels(FP.buffer, new Rectangle(x, y, width, height), new Point(), Image(graphic).getBuffer(), new Point(), true);
else
saved.copyPixels(FP.buffer, new Rectangle(x, y, width, height), new Point());
}
else
{
// paste stored part of the buffer
if (master && master.saved) FP.buffer.draw(master.saved, new Matrix( 1, 0, 0, 1, x, y ));
}
}
}