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:
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]
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.
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.
[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
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?
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.