PDA

View Full Version : same movieclips, different layouts



subquark
May 18th, 2003, 12:09 PM
arghh! This has to be so easy but I don't know how to approach it. Arrays!?! Function?!? There is an efficient way to do this but . . .

Okay I want to use the same movieclips (some are button movieclips) but be able to have a function lay them out at runtime in two (or more) layouts. Just the _x and _y position like in this example:

http://www.subquark.com/footer/layout.gif

I'd like to layout the mcs with just actionscript. So it can be hardwired into the movie's script with parameters A yielding layout A, et cetera.

something like this:


boxOne_mc._x = 100;
boxOne_mc._y = 100;

boxTwo_mc._x = 200;
boxTwo_mc._y = 100;

boxOne_mc._x = 300;
boxOne_mc._y = 100;

btnOne_mc.x = 5;
btnOne_mc.y = 100;


but all wrapped up in one function. Gee this is hard for me to explain and maybe I'm making this more difficult than it needs to be. :(

RvGaTe
May 18th, 2003, 05:17 PM
allright, i dont know if its this what you mean, but ill give it a shot... here we go...



function changeLayout(x){
if(x==1){
boxOne_mc._x = 100;
boxOne_mc._y = 100;
boxTwo_mx._x = 200;
boxTwo_mx._y = 100;
} else if (x==2){
boxOne_mc._x = 300;
boxOne_mc._y = 100;
boxTwo_mx._x = 5;
boxTwo_mx._y = 100;
}
}
// if you want to change the layout on the fly, just use this code:
// the parameter givin (in this case 1) will determine the layout
changeLayout(1)


i hope this is what you ment

subquark
May 18th, 2003, 06:30 PM
that is it! yes, yes, yes!!! thank you so much!!!!

RvGaTe, you RULE!!!!

thanks!!!!!!!!!!!!!! :thumb:

RvGaTe
May 18th, 2003, 06:31 PM
np dude :) (btw, did it really took 5 minutes to type that all? :P, i love Who's Online)

subquark
May 18th, 2003, 06:55 PM
almost 5 minutres, I also have two windows open on actionscript.org :geek:

thanks again!

23 seconds later . . .

Hawk
May 18th, 2003, 07:23 PM
it would be neat, and possible, to have this function and have a button to control the x variable, so they could change the layout on the button, but have each MC move with inertia so they slide into place when you change it..

that would be a neat extra to a site

subquark
May 18th, 2003, 07:28 PM
that would kick ***** and you could use a localSharedObject to place a cookie so that the site would look the same to that user, hmm, this sounds pretty interesting!

RvGaTe
May 19th, 2003, 09:43 AM
i goin to figure out the xtra you want, just hold on, could take 15min :)

ill post it when im done...

subquark
May 19th, 2003, 09:54 AM
this will check for a cookie:


// Get the cookie
so = sharedobject.getlocal("cookie");
// Get the user of the kookie and go to the frame number saved for this user.
if (so.data.user != undefined)
{
this.user = so.data.user;
trace("cookie exists!!!");
}
else
{
trace("cookie does not exist!!!");
}

RvGaTe
May 19th, 2003, 10:11 AM
alright, i figured it out, worked out pretty good and cool :)



// this prototype function is for making it all go smooth
// put the protytype and the changeLayout function on the main
// timeline, frame 1....
MovieClip.prototype.ease = function(x, y) {
speed = 5;
this.onEnterFrame = function() {
this._x += (x-this._x)/speed;
this._y += (y-this._y)/speed;
};
};
// here you determine the templates, just use:
// mc.ease(newx, newy)
function changeLayout(x) {
if (x == 1) {
number1.ease(300, 5);
number2.ease(50, 5);
number3.ease(500, 10);
} else if (x == 2) {
number1.ease(5, 300);
number2.ease(5, 50);
number3.ease(0, 0);
}
}
// to change the layout on a button, just use this actionscript on the button
// with X being the template
on(release){
changeLayout(X)
}


about the cookies... you need to do that on ur own, i never worked with cookies b4.. sorry

i hope i been allot of help :D

subquark
May 19th, 2003, 10:25 AM
kewl code!! thanks! I'll try it out.

RvGaTe
May 19th, 2003, 11:18 AM
here's a live preview:




goin to be my sig to :)

subquark
May 19th, 2003, 11:40 AM
i like it!! but what does it mean?

RvGaTe
May 19th, 2003, 11:59 AM
RvGaTe is a mix of my own name, and my previeus nickname (GaTeKeePeR)

R = René
v = van
GaTe = GaTeKeePeR

translated to english,
René from GaTeKeePeR

:)

subquark
May 19th, 2003, 01:49 PM
ha! my name is David Rene Miller (and my step dad is dutch: VandenBerg)

RvGaTe
May 19th, 2003, 04:50 PM
nice to meet you david :), my full name is René van Aerle (dutch :P)

subquark
May 19th, 2003, 05:05 PM
when I am done with the project I'm working on, I'll post it for you to see why I was asking these questions. although what you will see will not use your code at this point. it is a dummy layout for a prospective fulltime job.

i'll post it in a few hours . . .