Away3D
Well, I figured out that the way to re-size was to update the view. And the that you can center or re-position either positioning the flash.display.Sprite
container where the Away scene was added or the view it-self.
It's tricky thought cause you have to find out that the view's methods for scaleX
& scaleY
are 'DEAD END's, meaning that they are empty methods that make no change what so ever. So you really MUST & can change only the width
& height
properties.
here al list of all the DEAD END methods of theView3D
just as they appear in the source code:
// dead ends:
override public function set z(value : Number) : void {}
override public function set scaleZ(value : Number) : void {}
override public function set rotation(value : Number) : void {}
override public function set rotationX(value : Number) : void {}
override public function set rotationY(value : Number) : void {}
override public function set rotationZ(value : Number) : void {}
override public function set transform(value : Transform) : void {}
override public function set scaleX(value : Number) : void {}
override public function set scaleY(value : Number) : void {}
Starling
What worked in our project after experimentation of the team is the following:
Goal: To re-size a background just as it would work when setting the Size to percentage
the scale to:NO_BORDER
and the align to: Top Center
.
//Necessary variables
public var backgroundContainerStage:Starling;
public var anyOtherContainerStage:Starling;
public var stage3dProxy:Stage3DProxy;
public var scaleRatio:Number;
public var originalHeight:Number = 900;
// ... {HACK} ... {HACK}
// Add your Listeners in the constructor for Event.AddedToStage
// and set the handler to init... Or any other method you prefer to add the
// listener on the `Event.RESIZE`.
//
// Also populate the stage3DProxy how ever you wish.
// We did it this way:
//_stage3DProxy = Stage3DManager.getInstance(stage).getFreeStage3DProxy();
//
// ... {HACK} ... {HACK}
public function init(event:Event=null):void{
stage.addEventListener( Event.RESIZE, onResize, false, 0, true );
}
// The IMPORTANT PART !!!!!!!!
public function onResize():void {
scaleRatio = stage.stageHeight/originalHeight;
backgroundContainerStage.stage.stageWidth =
anyOtherContainerStage.stage.stageWidth =
stage3dProxy.width = stage.stageWidth;
// Need to get the Starling Sprite cause the the Starling instances don't allow to
// set values for their `x` and `y` properties.
var background: Sprite = backgroundContainerStage.getChildByName('background') as Sprite;
var uiContainer: Sprite = anyOtherContainerStage.getChildByName('uiContainer') as Sprite;
//First, RE-SIZE
background.scaleX = background.scaleY =
uiContainer.scaleX = uiContainer.scaleY = scaleRatio;
//Then, RE-POSITION top-Center
background.x =
uiContainer.x = stage.stageWidth - background.width >>1;
}