[AS3] Width Height Ratio Calc
private function updateWidthHeight():void {
var nMaxAreaWidth:Number = 800;
var nMaxAreaHeight:Number = 490;
var nMaxAreaRatio:Number = nMaxAreaWidth / nMaxAreaHeight;
var nW:Number;
var nH:Number;
nW = _player.getEpisodeWidth(); //_loader.stage.stageWidth; //_loader.content.width; // _mcSwf.width;
nH = _player.getEpisodeHeight(); //_loader.stage.stageHeight; //_loader.content.height; // _mcSwf.height;
var nWHRatio:Number = nW / nH;
// trace(“nW: ” + nW + “, nH: ” + nH);
// trace(“nMaxAreaRatio: “+nMaxAreaRatio+”, nWHRatio: “+nWHRatio);
/*
if (nMaxAreaRatio > nWHRatio) {
_mcSwf.height = nMaxAreaHeight;
_mcSwf.width = (nW*nMaxAreaHeight)/nH;
_mcSwf.x = (nMaxAreaWidth-_mcSwf.width)/2;
}
else if (nMaxAreaRatio < nWHRatio) {
_mcSwf.width = nMaxAreaWidth;
_mcSwf.height = (nH*nMaxAreaWidth)/nW;
_mcSwf.y = (nMaxAreaHeight-_mcSwf.height)/2;
}
/**/
if (_bGame) {
_mcSwf.x = (nMaxAreaWidth – nW) / 2;
_mcSwf.y = 0; // (nMaxAreaHeight – nH) / 2;
}
else {
_mcSwf.x = (nMaxAreaWidth-_mcSwf.width)/2;
_mcSwf.y = (nMaxAreaHeight-_mcSwf.height)/2;
}
/*
trace(“_mcSwf.width: “+_mcSwf.width+”, _mcSwf.height: “+_mcSwf.height);
/**/
}

Leave a Reply