Conditional on scale mc

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.

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

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();
}
}
};

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]

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.

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?
:stuck_out_tongue:

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?

ok,

book:colin moock’s adsg

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?

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.

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


lie_mc.easeScale(0, 0, 3);

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.

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

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.

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

http://www.d-steam.com/files/sunnysky.fla.zip
932k

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