PDA

View Full Version : Scaling a box using AS


Hopefooly
09-03-2003, 06:32 PM
im guessing this is relatively easy, but i havent been able to pull it off...none of my books have stuff on scripted motion really, so its not helping. but anyway heres the code:

on the MC

onClipEvent(load) {
this._xscale = 1;
this._yscale = 1;
size = 1
}
onClipEvent(enterFrame) {
while(size < 5) {
this._xscale += 1;
this._yscale += 1;
size++;
}
}


can anyone point out what im doing wrong? thanks in advance.

annexion
09-03-2003, 06:43 PM
onClipEvent(load) {
this._xscale = 1;
this._yscale = 1;
}
onClipEvent(enterFrame) {
if(this._xscale<50) {
this._xscale += 1;
this._yscale += 1;
}
}

You can shorten it up a bit by doing that ^. If you use an if loop it will increment one time per frame. So, at 30 fps it will increment 30 times in one second. So, as I have it it will take about 1 and 2/3rd seconds rather than 1/30th of a frame a while loop executes it in.

Hope that helps.

Hopefooly
09-03-2003, 07:38 PM
is there a way to script it so that it changes the x scale, then the y scale? so it expands left to right, then up to down...is it possible without actual animation?

annexion
09-03-2003, 07:49 PM
There sure is.

onClipEvent(load) {
this._xscale = 1;
this._yscale = 1;
}
onClipEvent(enterFrame) {
if(this._xscale<50) {
this._xscale += 1;
}else{
if(this._yscale<50){
this._yscale += 1;
}
}
}

As I said, I'm not sure if you're using MX or 5 so, if you are in fact using MX, you'll want to clear the enterFrame when it's done executing the necessary conditions.

Good luck.

Hopefooly
09-03-2003, 09:38 PM
thank you so much annexion, and i have one final question. Is it possible to have the upper left hand corner stay in place while the rest of it expands? thats my final question regarding this topic :)

PS: im using mx

annexion
09-04-2003, 02:12 AM
Yep, there is.

Go into that box movieclip and move the rectangle so that the top left corner is on the crosshairs that represent the center of the clip. You'll have to go back to the main stage and change the position, but it will accomplish exactly what you're looking for.

Good luck.