Hello all, Im in need of some help in converting a few blocks of code from AS2 to AS3 . I will not be using these codes in external .as files, and will need them to be used directly on the stage in the main timeline of the specific movieclips. One deals with conditional statement that scales a background image up when the browser window becomes larger than the specified stage size within the code, but remains the same size when on smaller monitors. Code is below:
if (Stage.width>1920 || Stage.height>1200)
{
mainSitebg._width = Stage.width;
mainSitebg._height = Stage.height;
mainSitebg._xscale > mainSitebg._yscale ?
mainSitebg._yscale = mainSitebg._xscale :
mainSitebg._xscale = mainSitebg._yscale;
}
var stageL:Object = new Object();
stageL.onResize = function() {
if (Stage.width>1920 || Stage.height>1200)
{
mainSitebg._width = Stage.width;
mainSitebg._height = Stage.height;
mainSitebg._xscale > mainSitebg._yscale ?
mainSitebg._yscale = mainSitebg._xscale :
mainSitebg._xscale = mainSitebg._yscale;
}
Stage.addListener(stageL);
The next bit of code deals with a parallax effect with individual movieclips. That code is below also:
orig_x = this._x;
orig_y = this._y;
profundidad = 20;
this.swapDepths(profundidad);
onEnterFrame = function() {
dest_x = (((210 - _root._xmouse)/400) * profundidad) + orig_x;
incr_x = (dest_x - this._x)/10;
this._x += incr_x;
dest_y = (((130 - _root._ymouse)/330) * profundidad) + orig_y;
incr_y = (dest_y - this._y)/10;
this._y += incr_y;
}
Ant help would be very much appretiated! Thank you to anyone that may help! Cheers! Jason
ignore
Ill give you the short version …make sure your background been load first then … i code it on the fly i didn’t test it but should be OK .
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
///then add addEventListener will fire only when re-size
stage.addEventListener(Event.RESIZE, onStageResize);
///first entry fire Re-size.
FullScreen(_itemToResize);
//when re-size.
function onStageResize(evt:Event):void {
FullScreen(_itemToResize);
}
function FullScreen(fixSize:MovieClip):void {
if (fixSize != null) {
// trace("Resizing image " + fixSize.name + "...");
fixSize.width = stage.stageWidth;
fixSize.height = stage.stageHeight;
if (fixSize.scaleX > fixSize.scaleY) {
fixSize.scaleY = fixSize.scaleX;
} else {
fixSize.scaleX = fixSize.scaleY;
}}}
Regarding the parallax should be almost the same just change mouseX, mouseY use
addEventListener(Event.ENTER_FRAME,myFunction);
function myFunction(event:Event) {
trace("Do Something");
}
Thank you very much tsafi for your help! I believe I understand on the conditional statement but the parallax I’m still not quit grasping. Would you be so kind as to show me that full edited code? Thanks again!
