Maxi...A box with animation in AS FLMX

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. :slight_smile:

Here we go again :slight_smile:

  1. Create a new, empty movieclip, place it anywhere on stage.

  2. Apply the following actionscript to it:

_root.targW = initialwidth;
_root.targH = intialheight;
onClipEvent(enterFrame){ = _root.targW-(_root.targW -; = _root.targH-(_root.targH -;

  1. 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.

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 !


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 ?

I think so Yes :smirk:

i try it also, it gets smaller and smaller

It should be…

_root.targW = initialwidth;
_root.targH = intialheight;
onClipEvent(enterFrame){ += (_root.targW -; += (_root.targH -;

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.

Mine works too, postatomic used it and worked fine … I don’t get why it doesn’t work for you … :-\

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 :slight_smile:

It won’t work because you can only set _width and _height in MX.

height = 400; //in pixels
height = 400/_height*100;
        _yscale +=  (height - _yscale)/10;

[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 ?

anybody ?

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: += 1 += 1
// these are text variables:
this.vheight = "height: "
this.vwidth = "width: "

what matters in the way the box grows is the registration point, on mine it was top left of the box…

<embed src= height=350 width=500 type=application/x-shockwave-flash>

here’s the fla btw:
right click and save as…

edit: wrong address

Thank you very much for your help

Heres, my typical method.

hey on that easeresize fla how would you change to code so you could load external swfs in to the box tha is resizing?

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…

[AS]//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
//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
//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
//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”);

thanks so much your awsome!! hope some day i can write wicked action script too


Meh, it’s not too difficult, just keep at it and study/practice/experiment often!