PDA

View Full Version : Automatically align MC to bottom of screen?



DeletedUser5
January 25th, 2004, 02:05 AM
I don't even know if this is possible or not... but here goes:

I have my movie embedded with 100% width 100% height in order to take up the entire browser window. Now what I would like is a MC to automatically align itself so that it stays at the bottom edge of the browser and adjusts itself whenever the browser window is resized.

Wishful thinking? :puzzled:

kode
January 25th, 2004, 04:38 AM
It's actually pretty easy. :)

my_mc.onResize = function() {
var bounds = this.getBounds(this._parent);
var yoffset = this._y-bounds.yMax;
this._y = Stage.height+yoffset;
};
Stage.addListener(my_mc);
Stage.scaleMode = "noScale";
Stage.align = "TL";
Where my_mc is the instance name of the movie clip that you want to align to the bottom of the stage. ;)

DeletedUser5
January 25th, 2004, 12:40 PM
Thank you kode! I really appreciate your help :pleased: Here's what the final code looks like:

Interface.onResize = function() {
var bounds = this.getBounds(this._parent);
var yoffset = this._y-bounds.yMax;
this._y = Stage.height+yoffset;
};
Interface.onEnterFrame = function() {
var bounds = this.getBounds(this._parent);
var yoffset = this._y-bounds.yMax;
this._y = Stage.height+yoffset;
};
Stage.addListener(Interface);
Stage.align = "TM";
Stage.scaleMode = "noScale";

I added onEnterFrame so it would be aligned to the bottom of the window as soon as the website loaded.

kode
January 25th, 2004, 01:25 PM
No problem. ;)

...And you don't need an onEnterFrame event handler, you can just call the onResize event handler. :P

Interface.onResize = function() {
var bounds = this.getBounds(this._parent);
var yoffset = this._y-bounds.yMax;
this._y = Stage.height+yoffset;
};
Stage.addListener(Interface);
Stage.scaleMode = "noScale";
Stage.align = "TL";
Interface.onResize();

upuaut
January 25th, 2004, 01:34 PM
and you're smart to say so Kode. Checking the same thing 24 times a second or so is a big waste of CPU clock speed when you only need to adjust when someone changes their browser window.

thanks from me too for this code. I was really interested in that question and answer.

kode
January 25th, 2004, 01:40 PM
...Yeah, I was like "what's the point of the onResize event handler if you end up using an onEnterFrame?". :P

My pleasure, David. =)

upuaut
January 25th, 2004, 01:47 PM
Well remember back when you still only had 17 posts and remember all the assinine things you did in the name of the gods of redundency.

well maybe you didn't.. but I remember doing the strangest things when I was a new Flasher. :)

Anyway Rojo.. good question. Obviously you're no newb or you wouldn't be using advanced actionscript in such a manner I hope the above didn't imply that :). Glad you got an answer and that it's working for ya.

kode
January 25th, 2004, 01:59 PM
Well, I'd just like to clarify that I wasn't trying to make fun of you or anything, Rojo. :)

...And I do remember those days, upuaut; good days, by the way. ;)

DeletedUser5
January 25th, 2004, 06:39 PM
Ah I see, thanks for pointing that out.

When it comes to actionscript I don't know what the hell I'm doing haha.

upuaut
January 26th, 2004, 01:18 AM
me either most days Rojo.

that's the fun for me.. as soon as I have a handle on one thing, I've learned twelve new things that confuse the hell out of me.

Kode.. I didn't think you were being insulting either.. just wanted to make ure rojo didn't. ;)

benswift
January 28th, 2004, 06:03 PM
I have been trying to solve this issue for months- I thought this code would be the answer but it is not. In fact it confuses me further-

using the above script to align a MC in a movie with the align parameter set to "TL" (top left) I get a result that aligns the MC to bottom left. In fact - anytime I set it to Top it appears at the bottom, and if I set it to Bottom it does not appear onscreen at all.

I've been wrestling with this for months.

I am using a main swf called body.swf with this code to control it:

// do not scale SWF
Stage.scaleMode = "Scale";
// align movie in top left corner
Stage.align = "TL";
// resize level 0 when browser resizes
this.onResize = function() {
this._width = Stage.width;
this._height = Stage.height;
};
Stage.addListener(this);
// initial resize of movie
this.onLoad = this.onResize;

it loads a few movies into different layers, the one I want to control alignment of is on the top. here's an example - this one the MC align is set to TL but as you can see it is aligning at bottom left.

http://www.nonoart.com/test/body.htmlhttp://www.nonoart.com/test/body.html

upuaut
January 29th, 2004, 08:23 AM
I'm really unsure of what your code is supposed to do, let alone how it's messing up. Sorry.

I'll see if I can look up each of those commands. Perhaps I'll see a simple error.