View Full Version : maxi...A box with animation in AS FLMX
Millad
July 6th, 2003, 05:55 AM
I have a simple box. I whant it to resize it self with nice smove animation using just Actionscript in Flash MX. I did see some tutorials here but I did not find whant I whant.
please see the attch. image. :)
Voetsjoeba
July 6th, 2003, 06:18 AM
Here we go again :)
1) Create a new, empty movieclip, place it anywhere on stage.
2) Apply the following actionscript to it:
onClipEvent(load){
_root.targW = initialwidth;
_root.targH = intialheight;
}
onClipEvent(enterFrame){
_root.box._width = _root.targW-(_root.targW - _root.box._width)/1.2;
_root.box._height = _root.targH-(_root.targH - _root.box._height)/1.2;
}
3) Whenever you want the box to grow bigger, use these actions:
_root.targW = width_you_want_it_to_grow_to;
_root.targH = height_you_want_it_to_grow_to;
This could be used on a button for example, like this:
on (release){
_root.targW = width_you_want_it_to_grow_to;
_root.targH = height_you_want_it_to_grow_to;
}
or, it could be on a frame, or whatever.
Millad
July 6th, 2003, 06:56 AM
Thanx but the box dont get bigger it gets smaller and very small without stopping ??? I did what u said !
maybe a example will be great !
Thanx:love:
Voetsjoeba
July 6th, 2003, 07:29 AM
Huh ? That's weird ... I've used that script a million times and it always worked ... Are you sure you set the variables to the right values ?
Millad
July 6th, 2003, 02:41 PM
I think so Yes :smirk:
Neo-Geo
July 6th, 2003, 03:14 PM
i try it also, it gets smaller and smaller
lostinbeta
July 6th, 2003, 03:33 PM
It should be...
onClipEvent(load){
_root.targW = initialwidth;
_root.targH = intialheight;
}
onClipEvent(enterFrame){
_root.box._width += (_root.targW - _root.box._width)/1.2;
_root.box._height += (_root.targH - _root.box._height)/1.2;
}
And don't forget to change initialheight and initialwidth to the number value you want your clip to start off at, otherwise it will return undefined and be 0.
Voetsjoeba
July 6th, 2003, 03:48 PM
Mine works too, postatomic used it and worked fine ... I don't get why it doesn't work for you ... :-\
Millad
July 6th, 2003, 04:54 PM
I tryd it agein but it dont get smaller now it gets big but not to big and with very smal animation, it dont move much.
if you tested it many times why not add a simple attch.
Please :)
[m]
July 6th, 2003, 07:42 PM
It won't work because you can only set _width and _height in MX.
onClipEvent(load){
height = 400; //in pixels
height = 400/_height*100;
}
onClipEvent(enterFrame){
_yscale += (height - _yscale)/10;
}
Millad
July 7th, 2003, 04:56 AM
[m] I do not understand how your code works. It will be much easyer to add a example fla. because I think is not hard to make one by you guys ? whats the problem ?
Millad
July 7th, 2003, 10:54 AM
anybody ?
mlk
July 7th, 2003, 11:35 AM
Here's a little something:
basically you have two frames in the movie clip and one tells the box to increment width and height by one - so the start and stop button actually stop the animation...
i could have made a function for this but im too lazy:
this.box._height += 1
this.box._width += 1
// these are text variables:
this.vheight = "height: "+this.box._height
this.vwidth = "width: "+this.box._width
what matters in the way the box grows is the registration point, on mine it was top left of the box....
<embed src=http://mlkdesign.free.fr/misc/kirupa/flashbox.swf height=350 width=500 type=application/x-shockwave-flash>
mlk
July 7th, 2003, 11:36 AM
here's the fla btw:
http://mlkdesign.online.fr/misc/kirupa/flashbox.fla
right click and save as....
edit: wrong address
Millad
July 8th, 2003, 11:41 AM
Thank you very much for your help
lostinbeta
July 8th, 2003, 12:22 PM
Heres, my typical method.
rlLife
September 4th, 2003, 01:44 PM
hey on that easeresize fla how would you change to code so you could load external swfs in to the box tha is resizing?
lostinbeta
September 4th, 2003, 03:17 PM
You can't load to the box clip otherwise it will overwrite the box clip, so what you will have to do is use createEmptyMovieClip() to create an empty movie clip to load to.
And you will have to reposition this empty clip when you resize so that the clip is in the upper left corner of the box (since loaded movies attach their upper left corner to the empty clip they load to).
The reposition and loading will have to take place after the resizing, so we can take care of that with an if statement (and a few other slight adjustments to the code).
We will also have to unload the current movie before it resizes so you don't have the old loaded movie showing while it is resizing.
And lastly we would have to set a new parameter to the function so you can choose what file you want to load.
And in the end we get...
//set variables
var endWidth = box._width;
var endHeight = box._height;
var speed = 5;
//creat empty clip to load to
this.createEmptyMovieClip("container", 1);
//create prototype function to resize the box
MovieClip.prototype.resizeTo = function(w, h, file) {
//unload current movie loaded to container clip
container.unloadMovie();
//run the following code onEnterFrame
this.onEnterFrame = function() {
//eW and eH variables to hold the final end width and end height
eW = Math.round(w-this._width);
eH = Math.round(h-this._height);
//resize the clips with easing
this._width += ew/speed;
this._height += eH/speed;
//if the eW and eH variables equal 0
if ((ew && eh) == 0) {
//give notice when finished resizing
trace("resized");
//set the box to the final size
this._width = w;
this._height = h;
//stop running the onEnterFrame
delete this.onEnterFrame;
//reposition container clip to upper left corner of box
//do this because the loaded movie attaches it's upper left corner to the clip
container._x = this._x-(this._width/2);
container._y = this._y-(this._height/2);
//load the file provided in the file parameter of the prorotype
container.loadMovie(file);
}
};
};
//use buttons to change the width and height.
button1.onPress = function() {
box.resizeTo(200, 100, "file1.swf");
};
button2.onPress = function() {
box.resizeTo(500, 300, "file2.swf");
};
button3.onPress = function() {
box.resizeTo(10, 10, "file3.swf");
};
rlLife
September 4th, 2003, 10:50 PM
thanks so much your awsome!! hope some day i can write wicked action script too
rL
lostinbeta
September 4th, 2003, 10:55 PM
Meh, it's not too difficult, just keep at it and study/practice/experiment often!
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.