flash onResize Q???
- Started
- Last post
- 16 Responses
- wwfc
Afternoon! I am hoping that someone might be able to put me right with this...
I have a movieclip on the stage that is called "CENTERpages" - within that MC is an MXP/Component that sits central to the stage.
It all works fine until the stage gets resized - when the resize happens the component jumps to the top of the screen with half of it off the stage!
I have tried to work it out using this code:
///////////STAGE...
Stage.align = "TL";
Stage.scaleMode = "noscale";
Stage.addListener( this );
function onResize(){myMENU._x = 0;
myMENU._y = Math.floor(0);
myMENU.menuCONTENT.bgMENU._width = Math.floor(Stage.width);
myMENU.menuCONTENT.RBUTTON._x = Math.floor(Stage.width);CENTERpages._x = Stage.width / 2 - CENTERpages._width / 2;
CENTERpages._y = Stage.height / 2 - CENTERpages._height / 2;
world._x = Stage.width / 2 - world._width / 2;
world._y = Stage.height / 2 - world._height / 2;
centerX = Stage.width/2; // **** ADD HERE
centerY = Stage.height/2; // **** ADD HERE
}
onResize();and if I add these lines:
CENTERpages.componentname._x = Stage.width / 2 - CENTERpages.componentname._width / 2;
CENTERpages.componentname.._y = Stage.height / 2 - CENTERpages.componentname._heigh... / 2;it doesn't work - and I thought it would - is there any rules when trying to centre components?
Be grateful for any pointers or advice on this - t'is doing my fruit in!
- kult0
I have to run out for a sec, and this isn't answering your question, but you should not be calculating the Stage.width / 2 every single time.
Calculate it once at the top of your loop, set it to a variable, and pass it around where necessary.
It's not as noticeable since you're only doing it in onResize events, but if you were to have an animated positioning (like in a frame event handler loop) it would really speed things up for you.
- wwfc0
...thanks Kult - appreciate the reply, I didn't realise there was a better way of doing it - bits have been added as the project has evolved - so I have added objects as needed - and added the code as it has evolved - all the elements that need to be centered do centre apart from this damned component :-(
Anyone see what I am doing wrong/not doing?
- maximillion_0
you might want to try using parenthesis on yr calcs for example
CENTERpages._y = Stage.height / 2 - CENTERpages._height / 2;
would be
CENTERpages._y = (Stage.height / 2) - (CENTERpages._height / 2);
- maximillion_0
im not convinced that you dont want to calc half the stagewidth on every resize. what happens if the stage width chnages?
- I didn't say that dude, I meant don't calculate it every single line. Store it to a variable.kult
- wwfc0
...hi maximillion_ I am trying to keep all of the elements within the CENTERpages MC - I need the content to always sit slap bang in the centre - which it does apart from the component.
- wwfc0
...I read somewhere that component jump back to a 0,0 reference point on resize - but I don't seem to be able to find a solution to it - I thought it would bee straight forward enough - but as you can see by my posting - it's not!
- fugged0
if the component is always repositioning itself to 0,0 and all else fails, create an empty movieclip / or sprite (if you are using as3) and add the component as a child to the new clip. unless the component is doing some sort of localToGlobal coordinate space conversion, you should be able to just position the parent clip and allow the component it be a dick..
- wwfc0
...is that possible with as2? the whole thing is set up for as2
- fugged0
are you adding the component dynamically, or manually placing on the stage?
- kult0
Fugged is correct. I usually don't use components, but if it has some abnormal repositioning behavior, and doesn't fuck around with parent/child space coordinates, then nesting it inside your own empty movieclip should do the trick.
- maximillion_0
yr code should throw an error - theres a double dot
CENTERpages.componentname.._y = Stage.height / 2 -
should be
CENTERpages.componentname._y = Stage.height / 2 -and what kult means is something like this
var sw:Number = Stage.width/ 2
and then replace all the other calculations of "stage width/2"with "sw"
- wwfc0
...as a rule I try to avoid components - but this case it is the only option!
sorry the double dot is me typing like a chimp in boxing gloves - the actual script in the fla doesn't have that
The component is placed onto the stage/timeline in the MC
I would have thought that having it within the CENTERpages clip, with that clip being centered would have kept the components relative position - shows what I know!"and what kult means is something like this
var sw:Number = Stage.width/ 2
and then replace all the other calculations of "stage width/2"with "sw""...I sort of get it - and equally sort of don't! - sorry for being a doughnut!
So how should it look if done right?
- kult0
Heh, basic programming man!
var bob:Number = 5;
var dole:Number = 10;this.x = bob + dole;
that.x = bob + dole;
penis.x = this.x + that.x - bob;I'm sure you can extrapolate from there! ;)
- wwfc0
***fires up extrapolator***
okay I'll see if I can get it sorted - thanks for the time taken and the replies amigos ;_)
- T-Dawg0
It might have something to do with the registration point of your movieclip, It might be top-left or something of the sort, which would throw things off. you'll want to make sure everything is at a centered registration.
- wwfc0
...I'll double check - it should all be centred - but that said, tired eyes n' all...
cheers Daaawg ;-)