View Full Version : [MX2]Change the size in action script
scdlt
October 17th, 2003, 09:07 PM
Here is what I have. I made a box that is 3x3px and it fades in, now I want it to change size from 3x3 to 300x300px. Now how would this be done? here is my code so far:
// create the box
_root.createEmptyMovieClip("Box", 100);
//starting alpha
Box._alpha = 0;
//box
_root["Box"].lineStyle(2, 0x2D3E34, 100);
_root["Box"].beginFill(0xA2BBAD, 100);
_root["Box"]._x=5;
_root["Box"]._y=5;
_root["Box"].moveTo(0, 0);
_root["Box"].lineTo(3, 0);
_root["Box"].lineTo(3, 3);
_root["Box"].lineTo(0, 3);
_root["Box"].endFill(0, 0);
//change alpha
speed = 5
Box.onEnterFrame = function ()
{
if (this._alpha < 100){
this._alpha += speed;}
else{
delete this.onEnterFrame;}
}
I want the box to change size while it is fading in.
So fare I've tried scale and width but those change the border size too, which is really annoying because I end up with a 100px border and a 100px box, not exactly what I was going for.
Yeldarb
October 17th, 2003, 09:39 PM
is it required that everything is done in actionscript, or could you make a box and just increase the height and width?
DerickLemos
October 17th, 2003, 10:33 PM
Do you want to do the box to increase of size?
Yeldarb
October 17th, 2003, 11:46 PM
im making an FLA for you that is just an mc that increases in size while fading in.
Yeldarb
October 17th, 2003, 11:59 PM
ok, here it is, it's not entirely actionscript, but all of the motion is done with AS.
DerickLemos
October 18th, 2003, 12:05 AM
// create the box
_root.createEmptyMovieClip("Box", 100);
//starting alpha
Box._alpha = 0;
//box
_root["Box"].lineStyle(1, 0x2D3E34, 100);
_root["Box"].beginFill(0xA2BBAD, 100);
_root["Box"]._x = 5;
_root["Box"]._y = 5;
_root["Box"].moveTo(0, 0);
_root["Box"].lineTo(3, 0);
_root["Box"].lineTo(3, 3);
_root["Box"].lineTo(0, 3);
_root["Box"].endFill(0, 0);
//change alpha
speed = 5;
Box.onEnterFrame = function() {
if (this._alpha<100) {
this._alpha += speed;
} else {
delete this.onEnterFrame;
}
this._height=this._height+(300-this._height)*.2;
this._width=this._width+(300-this._width)*.2;
};
Yeldarb
October 18th, 2003, 12:11 AM
derick, that will never stop growing, it will continue to grow in infinitely small increments and NEVER get to 300 :P though it will be incredibly close...
Voetsjoeba
October 18th, 2003, 03:26 AM
_root.createEmptyMovieClip("Box", 100);
with (_root.Box) {
_alpha = 0;
lineStyle(0, 0x2D3E34, 100);
beginFill(0xA2BBAD, 100);
_x = 175;
_y = 175;
// For a registration point in the centre
/*moveTo(-1.5, -1.5);
lineTo(1.5, -1.5);
lineTo(1.5, 1.5);
lineTo(-1.5,1.5)
lineTo(-1.5, -1.5);*/
moveTo(0, 0);
lineTo(3, 0);
lineTo(3, 3);
lineTo(0, 3);
endFill(0, 0);
}
speed = 5;
Box.onEnterFrame = function() {
this._alpha += speed;
this._width>299 && this._width<301 ? this._alpha>=100 ? delete this.onEnterFrame : this._alpha += speed : this._width=this._height=300-(300-this._width)/1.2;
updateAfterEvent();
};
Here's the same code, not using the tertiary operator:
_root.createEmptyMovieClip("Box", 100);
with (_root.Box) {
_alpha = 0;
lineStyle(0, 0x2D3E34, 100);
beginFill(0xA2BBAD, 100);
_x = 175;
_y = 175;
// For a registration point in the centre
/*moveTo(-1.5, -1.5);
lineTo(1.5, -1.5);
lineTo(1.5, 1.5);
lineTo(-1.5,1.5)
lineTo(-1.5, -1.5);*/
moveTo(0, 0);
lineTo(3, 0);
lineTo(3, 3);
lineTo(0, 3);
endFill(0, 0);
}
speed = 5;
Box.onEnterFrame = function() {
this._alpha += speed;
if (this._width>299 && this._width<301) {
if (this._alpha>=100) {
delete this.onEnterFrame;
} else {
this._alpha += speed;
}
} else {
this._width = this._height=300-(300-this._width)/1.2;
}
updateAfterEvent();
};
scdlt
October 18th, 2003, 12:34 PM
Ah! perfect! Thank you.
Voetsjoeba
October 18th, 2003, 01:11 PM
You're welcome =)
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.