# Conditional on scale mc

**URL:** <https://forum.kirupa.com/t/conditional-on-scale-mc/21112>\
**Category:** Uncategorized\
**Created:** [May 17, 2003, 8:11am UTC](https://forum.kirupa.com/t/conditional-on-scale-mc/21112 "2003-05-17T08:11:53Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![smacklemore](https://avatars.discourse-cdn.com/v4/letter/s/b4bc9f/32.png) [@smacklemore](https://forum.kirupa.com/u/smacklemore)\
**Post date:** [May 17, 2003, 8:11am UTC](https://forum.kirupa.com/t/conditional-on-scale-mc/21112/1 "2003-05-17T08:11:53Z")

</div>

This is my first post to this forum. I can usually find what I need by searching. Not this time.

I’m scaling an mc with a script.  
This is on the timeline of the parent:

stop();  
MovieClip.prototype.easeScale = function (finalWidth, finalHeight, speed) {  
this.onEnterFrame =function () {  
this.\_width += Math.floor ((finalWidth- this.\_width )/speed);  
this.\_height += Math.floor ((finalHeight- this.\_height )/speed);  
};  
};  
mask\_mc.onEnterFrame = function () {  
this.easeScale(587, 425, 3);  
};

I want to trigger another mc to play on the root once mask\_mc reaches its finalHeight. I’ve tried if statements, but nothing really works. I feel dumb.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 17, 2003, 8:57am UTC](https://forum.kirupa.com/t/conditional-on-scale-mc/21112/2 "2003-05-17T08:57:14Z")

</div>

[AS]  
mask\_mc.onEnterFrame = function() {  
this.easeScale(587, 425, 3);  
//e is the error, 0.5, 0.2,… you’ll have  
//to test it to see how it behaves  
if (Math.abs(this.\_height - finalHeight) \< e) {  
//do something  
//  
//and you may also want to delete the method:  
delete this.onEnterFrame;  
}  
};  
[/AS]

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 19, 2003, 4:44am UTC](https://forum.kirupa.com/t/conditional-on-scale-mc/21112/3 "2003-05-19T04:44:26Z")

</div>

Thanks a lot for replying. Sorry for the late responce. I thought I would get an email notice.

Anyway, I follow your logic, but it didn’t seem to work. If I turn the \< around to be \> it triggers the action immediately. I’m guessing something needs to tell the if statement to keep checking until it’s at the desired height.

Then again maybe I did something wrong. Just in case here’s all of the code on that frame including yours:

stop();  
MovieClip.prototype.easeScale = function (finalWidth, finalHeight, speed) {  
this.onEnterFrame =function () {  
this.\_width += Math.floor ((finalWidth- this.\_width )/speed);  
this.\_height += Math.floor ((finalHeight- this.\_height )/speed);  
};  
};  
mask\_mc.onEnterFrame = function () {  
this.easeScale(587, 425, 3);  
if (Math.abs (this.\_height - finalHeight) \< 1) {  
with(\_root.sidetext\_mc){  
play();  
}  
}  
};

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 19, 2003, 8:02am UTC](https://forum.kirupa.com/t/conditional-on-scale-mc/21112/4 "2003-05-19T08:02:48Z")

</div>

sorry… you can’t have two onEnterFrame() applied to the same object…  
now I tried this with a movieClip and it works. But I had to increase the e to 3.  
[AS]  
stop();  
MovieClip.prototype.easeScale = function(finalWidth, finalHeight, speed) {  
this.onEnterFrame = function() {  
this.\_width += Math.floor((finalWidth - this.\_width) / speed);  
this.\_height += Math.floor((finalHeight - this.\_height) / speed);  
if (Math.abs(this.\_height - finalHeight) \< 3) {  
trace(“done”);  
with (\_root.sidetext\_mc) {  
play();  
}  
}  
};  
};  
mask\_mc.easeScale(587, 425, 3);  
[/AS]  
As this is a method, and you may want to use it in other occasions, you define the method with more arguments:

[AS]  
stop();  
//define the method with two optional parameters  
//a function and an argument (you can define it with 0 or more arguments!)  
MovieClip.prototype.easeScale = function(finalWidth, finalHeight, speed, f, arg) {  
this.onEnterFrame = function() {  
this.\_width += Math.floor((finalWidth - this.\_width) / speed);  
this.\_height += Math.floor((finalHeight - this.\_height) / speed);  
if (Math.abs(this.\_height - finalHeight) \< 3) {  
return f.call(this, arg);  
}  
};  
};  
//define a function  
function myFunction() {  
trace(“done”);  
with (\_root.sidetext\_mc) {  
play();  
}  
}  
//call the function you want to preform as an argument of the method:  
//in this case you don’t need an argument  
mask\_mc.easeScale(587, 425, 3, myFunction);  
//here’s and exampe with an argument  
function myFunction(word) {  
trace(word);  
with (\_root.sidetext\_mc) {  
play();  
}  
}  
mask\_mc.easeScale(587, 425, 3, myFunction, “done”);  
[/AS]

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 19, 2003, 4:20pm UTC](https://forum.kirupa.com/t/conditional-on-scale-mc/21112/5 "2003-05-19T16:20:44Z")

</div>

Thanks, Nunomira. It worked! However, I had to get rid of the trace or else I got “done” 'til infinity, but otherwise I’m a happy guy.

I give this forum 5 stars. 'Til next time.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 19, 2003, 4:52pm UTC](https://forum.kirupa.com/t/conditional-on-scale-mc/21112/6 "2003-05-19T16:52:50Z")

</div>

sure, the trace action is only to help you debug.  
when you publish it, the trace() is ignored

why is the forum the one to receive the stars?  
😛

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 20, 2003, 6:35am UTC](https://forum.kirupa.com/t/conditional-on-scale-mc/21112/7 "2003-05-20T06:35:49Z")

</div>

My bad. You get all the stars. Thanks so much for learnin’ me something.

I’m really struggling with AS right now, but this goes a long way to helping me understand it. I have no computer language background at all, and am totally in awe of people like you who use it so gracefully. Seriously.

While I have your attention, if it’s not too much to ask… I’ve got three buttons inside of three seperate movie clips that I’ve moved using a similar script.

When I try to do anything else with these movie clips (i.e. go to a new key frame) the script seems to reset itself and move them again.

I’m assuming this is caused by the onEnterFrame. I thought using the delete this.onEnterFrame you suggested earlier would cure this problem, but it hasn’t.

Any suggestions? Any good books on Action Script?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 20, 2003, 8:33am UTC](https://forum.kirupa.com/t/conditional-on-scale-mc/21112/8 "2003-05-20T08:33:27Z")

</div>

ok,

book:[colin moock’s adsg](http://www.moock.org/asdg/)

If you’ve stopped resizing the movieClip, you should use the delete this.onEnterFrame;

If you delete the method, you should be able to do whatever you want… what is that?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 20, 2003, 4:59pm UTC](https://forum.kirupa.com/t/conditional-on-scale-mc/21112/9 "2003-05-20T16:59:27Z")

</div>

I must be really clueless because I’ve tried sticking the delete this.onEnterFrame in every logical (to me) place. Here’s the code on frame 2 of cds\_mc which contains lie\_mc, fagra\_mc and mindful\_mc:

stop();  
MovieClip.prototype.easeScale = function (finalx, finaly, speed) {  
this.onEnterFrame =function () {  
this.\_x += Math.floor ((finalx- this.\_x )/speed);  
this.\_y += Math .floor ((finaly- this .\_y )/speed);  
if (Math.abs (this.\_y - finaly) \< 3) {  
delete this.onEnterFrame;  
}  
};  
};

lie\_mc.onEnterFrame = function () { this.easeScale(0, 0, 3);  
};  
fagra\_mc.onEnterFrame = function () { this.easeScale(144, 0, 4);  
};  
mindful\_mc.onEnterFrame = function () { this.easeScale(288, 0, 5);  
};

I also tried, out of desperation, deleting each mc’s onEnterFrame (i.e., delete mindful\_mc.onEnterFrame) with no luck.

Thanks for the book recommendation.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 20, 2003, 6:49pm UTC](https://forum.kirupa.com/t/conditional-on-scale-mc/21112/10 "2003-05-20T18:49:19Z")

</div>

[AS]  
stop();  
MovieClip.prototype.easeScale = function (finalx, finaly, speed) {  
this.onEnterFrame =function () {  
this.\_x += Math.floor ((finalx- this.\_x )/speed);  
this.\_y += Math .floor ((finaly- this .\_y )/speed);  
if (Math.abs (this.\_y - finaly) \< 3) {  
//correct, goes here  
delete this.onEnterFrame;  
}  
};  
};  
[/AS]  
but you don’t call the method you defined above, like that.  
you already have the onEnterFrame() inside it

just this, right?

```auto

lie_mc.easeScale(0, 0, 3);

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 20, 2003, 7:51pm UTC](https://forum.kirupa.com/t/conditional-on-scale-mc/21112/11 "2003-05-20T19:51:44Z")

</div>

Oops. Uh, I knew that. Ok, I changed it to match your example, but no change in behavior. Is it possible to delete the MovieClip.prototype.easeScale? Any thoughts?

Thanks again.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 20, 2003, 8:46pm UTC](https://forum.kirupa.com/t/conditional-on-scale-mc/21112/12 "2003-05-20T20:46:10Z")

</div>

can’t you upload a fla with what you’re trying to do?  
Just this piece?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 20, 2003, 10:06pm UTC](https://forum.kirupa.com/t/conditional-on-scale-mc/21112/13 "2003-05-20T22:06:14Z")

</div>

This is weird, but when I took the movie clip into a new fla file it worked. ??? I’m uploading both the seperated one and the whole darn thing so you can compare.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 20, 2003, 10:12pm UTC](https://forum.kirupa.com/t/conditional-on-scale-mc/21112/14 "2003-05-20T22:12:07Z")

</div>

the other one was too big. Here’s a link to it:

[http://www.d-steam.com/files/sunnysky.fla.zip](http://www.d-steam.com/files/sunnysky.fla.zip)  
932k

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 20, 2003, 11:31pm UTC](https://forum.kirupa.com/t/conditional-on-scale-mc/21112/15 "2003-05-20T23:31:41Z")

</div>

Ok, I figured it out. I had to delete all of the movement methods in all the movie clips or it would refer back to them since they have the same name.

I didn’t realize these things were global. Silly me.

Thanks for your help, time and patience.🙂
