I had several ideas that went from calling and actionscript function from javascript using ExternalInterface, to passing FlashVars to the swf just to let the swf know what is the size of the div, to a more simple idea.
here goes.
Have 1 MovieClip as the background and 1 MoveClip containing the head.
I think your best bet would be the "This is the flash movie on top" option from your example. Your best will be setting
stage.scaleMode = StageScaleMode.NO_SCALE;
or
stage.scaleMode = StageScaleMode.SHOW_ALL;
The idea is to have content scaled proportionally.
Then you would add an event listener for the resize event and scale/redraw the background.
stage.addEventListener(Event.RESIZE, stageResizeHandler);
function stageResizeHandler(event:Event = null):void{
//assuming your background is called "background"
background.width = stage.stageWidth;
background.height = stage.stageHeight;
//if content needs recentering, assuming "content" is the name used
content.x = (stage.stageWidth - content.width) * .5;
content.y = (stage.stageHeight - content.height * .5;
}
I've set a default for the event handler argument so you can call that function withouth dispatching an event
e.g.
stageResizeHandler();
instead of
stage.dispatchEvent(new Event(Event.RESIZE));
You might need to call that function when you initiallize, not sure.
Also you'll need to resize the content proportionally depending on the size of the stage. so here's some code I tested:
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
stage.addEventListener(Event.RESIZE, stageResizeHandler);
stageResizeHandler();
function stageResizeHandler(event:Event = null):void{
//resize bg
bg.width = stage.stageWidth;
bg.height = stage.stageHeight;
//scale proportionally
if(content.width > stage.stageWidth || content.height > stage.stageHeight){
var ratio:Number = getRatio(content);
if(stage.stageWidth > stage.stageHeight){
content.height = stage.stageHeight;
content.width = content.height * ratio;
}else
if(stage.stageWidth < stage.stageHeight){
content.width = stage.stageWidth;
content.height = content.width / ratio;
}
}else {
content.scaleX = content.scaleY = 1;
}
//centre
content.x = (stage.stageWidth - content.width) * .5;
content.y = (stage.stageHeight - content.height) * .5;
}
function getRatio(target:MovieClip):Number{
var ratio:Number;
target.width > target.height ? ratio = (target.width / target.height) : ratio = (target.height / target.width);
return ratio;
}
Unfortunately I've noticed a some flickering on certain sizes. I'm guessing that the scaling and the fact the the ratio changes often depending on how you resize.