functions work only once? what I am doing wrong?

  • tykomusic
  • Newbie
  • Newbie
  • User avatar
  • Posts: 6
  • Loc: Estes Park, CO USA

Post 3+ Months Ago

so,

when i rollOver the movieClip buttons, they fade in and out once...beautifully, mind you, but still only once...any ideas?

Code: [ Select ]
//fade out function[/color]
function fadeOut(targetClip, minFade, speed) {
    targetClip._alpha -= speed;
    if (targetClip._alpha<=minFade) {
        targetClip._alpha = minFade;
        clearInterval(fadeInterval);
    }
}
//
//fade out event[/color]
invisBUp.onRollOver = function() {
    var fadeInterval = setInterval(fadeOut, 80, fadeUp, 0, 10);
};
//
//fade in function[/color]
function fadeIn(targetClip2, maxFade, speed2) {
    targetClip2._alpha += speed2;
    if (targetClip2._alpha == speed2) {
        targetClip2._alpha = maxFade;
        clearInterval(fadeInterval2);
    }
}
//
//fade in event[/color]
invisBUp.onRollOut = function() {
    var fadeInterval2 = setInterval(fadeIn, 80, fadeUp, 100, 20);
};
  1. //fade out function[/color]
  2. function fadeOut(targetClip, minFade, speed) {
  3.     targetClip._alpha -= speed;
  4.     if (targetClip._alpha<=minFade) {
  5.         targetClip._alpha = minFade;
  6.         clearInterval(fadeInterval);
  7.     }
  8. }
  9. //
  10. //fade out event[/color]
  11. invisBUp.onRollOver = function() {
  12.     var fadeInterval = setInterval(fadeOut, 80, fadeUp, 0, 10);
  13. };
  14. //
  15. //fade in function[/color]
  16. function fadeIn(targetClip2, maxFade, speed2) {
  17.     targetClip2._alpha += speed2;
  18.     if (targetClip2._alpha == speed2) {
  19.         targetClip2._alpha = maxFade;
  20.         clearInterval(fadeInterval2);
  21.     }
  22. }
  23. //
  24. //fade in event[/color]
  25. invisBUp.onRollOut = function() {
  26.     var fadeInterval2 = setInterval(fadeIn, 80, fadeUp, 100, 20);
  27. };


Peace

tykomusic

credits: this scripting was taken from lostinbeta, and I thank him for it...i would like to give credit where credit is due...
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • lostinbeta
  • Guru
  • Guru
  • User avatar
  • Posts: 1402
  • Loc: Philadelphia, PA

Post 3+ Months Ago

The setInterval method of doing this isn't really that efficient, when I posted that originally it was to fade button symbols and not movieclip symbols.... since button symbols don't support the onEnterFrame handler.


Your code is probably having conflictions with the setIntervals... but really I don't want to bother figuring it out since I am going to offer up a more efficient method.

Code: [ Select ]
MovieClip.prototype.fadeIn = function(maxFade, speed2) {
    this._alpha += speed2;
    if (this._alpha == speed2) {
        this._alpha = maxFade;
        delete this.onEnterFrame;
    }
};
MovieClip.prototype.fadeOut = function(minFade, speed) {
    this._alpha -= speed;
    if (this._alpha<=minFade) {
        this._alpha = minFade;
        delete this.onEnterFrame;
    }
};
invisBUp.onRollOver = function() {
    fadeUp.onEnterFrame = function() {
        this.fadeOut(0, 10);
    };
};
invisBUp.onRollOut = function() {
    fadeUp.onEnterFrame = function() {
        this.fadeIn(100, 20);
    };
};
  1. MovieClip.prototype.fadeIn = function(maxFade, speed2) {
  2.     this._alpha += speed2;
  3.     if (this._alpha == speed2) {
  4.         this._alpha = maxFade;
  5.         delete this.onEnterFrame;
  6.     }
  7. };
  8. MovieClip.prototype.fadeOut = function(minFade, speed) {
  9.     this._alpha -= speed;
  10.     if (this._alpha<=minFade) {
  11.         this._alpha = minFade;
  12.         delete this.onEnterFrame;
  13.     }
  14. };
  15. invisBUp.onRollOver = function() {
  16.     fadeUp.onEnterFrame = function() {
  17.         this.fadeOut(0, 10);
  18.     };
  19. };
  20. invisBUp.onRollOut = function() {
  21.     fadeUp.onEnterFrame = function() {
  22.         this.fadeIn(100, 20);
  23.     };
  24. };
  • tykomusic
  • Newbie
  • Newbie
  • User avatar
  • Posts: 6
  • Loc: Estes Park, CO USA

Post 3+ Months Ago

lostinbeta,

Thanks for the modification...that works great.

The one thing about passing prarameters that I don't understand is, how does Flash know to attribute a time factor to the parameter that I am calling "speed"? Is this a parameter that is specific to the _alpha property, and always occurs in the second place holder after the transparent value?[/B]

If my assumption is correct, where can I get a table of parameters for each property, method, etc.?

You are the best,

tykomusic[/b]
  • lostinbeta
  • Guru
  • Guru
  • User avatar
  • Posts: 1402
  • Loc: Philadelphia, PA

Post 3+ Months Ago

Flash doesn't attribute a time factor to the speed argument, the code in the function block interprets that
Code: [ Select ]
this._alpha += speed2;
that basically says this._alpha = this._alpha + whatever value you give to the speed2 argument. So depending on what number you put in there it will increment faster or slower.

Function arguments are user defined, speed is just a name so that YOU will know what it does. And yes, it's position in the argument list is important.

Example:
Code: [ Select ]
function test(val1, val2, val3, shibbynakanaka) {
    trace("val1: "+val1);
    trace("val2: "+val2);
    trace("val3: "+val3);
    trace("shibbynakanaka: "+shibbynakanaka);
}
test(1, 76, "elephant", 'tamper evident seal');
/*returns
val1: 1
val2: 76
val3: elephant
shibbynakanaka: tamper evident seal
*/
  1. function test(val1, val2, val3, shibbynakanaka) {
  2.     trace("val1: "+val1);
  3.     trace("val2: "+val2);
  4.     trace("val3: "+val3);
  5.     trace("shibbynakanaka: "+shibbynakanaka);
  6. }
  7. test(1, 76, "elephant", 'tamper evident seal');
  8. /*returns
  9. val1: 1
  10. val2: 76
  11. val3: elephant
  12. shibbynakanaka: tamper evident seal
  13. */


[edit]

The order you type them when calling the function does matter, but the order you call them within the function doesn't matter.

Example:
Code: [ Select ]
function test(val1, val2, val3, shibbynakanaka) {
    trace("val3: "+val3);
    trace("val1: "+val1);
    trace("shibbynakanaka: "+shibbynakanaka);
    trace("val2: "+val2);
}
test(1, 76, "elephant", 'tamper evident seal');
/*returns
val3: elephant
val1: 1
shibbynakanaka: tamper evident seal
val2: 76
*/
  1. function test(val1, val2, val3, shibbynakanaka) {
  2.     trace("val3: "+val3);
  3.     trace("val1: "+val1);
  4.     trace("shibbynakanaka: "+shibbynakanaka);
  5.     trace("val2: "+val2);
  6. }
  7. test(1, 76, "elephant", 'tamper evident seal');
  8. /*returns
  9. val3: elephant
  10. val1: 1
  11. shibbynakanaka: tamper evident seal
  12. val2: 76
  13. */



And also, the argument values are only available within the function block.... so you don't really have to worry about having a unique name (like you used speed and speed2 in your script, they could both just be speed because only the code within the function can read that value when it's called anyway so there are no conflictions).
[/edit]
  • tykomusic
  • Newbie
  • Newbie
  • User avatar
  • Posts: 6
  • Loc: Estes Park, CO USA

Post 3+ Months Ago

Ok...wow...

I think I better take tonight, after work, to digest this one. Thanks for the explanation.

I will be getting back to you on this one.

tykomusic
  • lostinbeta
  • Guru
  • Guru
  • User avatar
  • Posts: 1402
  • Loc: Philadelphia, PA

Post 3+ Months Ago

It's really not at all complicated once it clicks. Writing functions is like breathing to me now...lol.
  • eurosickwitit
  • Beginner
  • Beginner
  • eurosickwitit
  • Posts: 62

Post 3+ Months Ago

lostinbeta, how long did it take to learn AS for you and what did you use? Any specific books?
  • lostinbeta
  • Guru
  • Guru
  • User avatar
  • Posts: 1402
  • Loc: Philadelphia, PA

Post 3+ Months Ago

Almost 3 years and still learning. No books really, just google searches on subjects I was interested in tackling, and the ActionScript Reference (built into Flash or found online at http://www.macromedia.com/support/flash ... ictionary/ )

I kinda went down the list in the AS Reference and learned what each thing was and how it worked and I tried to make something that used it. Once I learned what things were individually I started combining things and learning more about how they work.

Forums are a great place to learn too.
  • eurosickwitit
  • Beginner
  • Beginner
  • eurosickwitit
  • Posts: 62

Post 3+ Months Ago

Yeah forums are for sure. You get to see how people soved their problems and possibly watch out for those mistakes in the future.
  • eurosickwitit
  • Beginner
  • Beginner
  • eurosickwitit
  • Posts: 62

Post 3+ Months Ago

Yeah forums are for sure. You get to see how people soved their problems and possibly watch out for those mistakes in the future.
  • tykomusic
  • Newbie
  • Newbie
  • User avatar
  • Posts: 6
  • Loc: Estes Park, CO USA

Post 3+ Months Ago

lostinbeta,

So, I have two movieClips on the stage that have the following code on the first frame of their timelines:

Code: [ Select ]
MovieClip.prototype.fadeIn = function(maxFade, speed2) {
  this._alpha += speed2;
  if (this._alpha == maxFade) {
   this._alpha = maxFade;
   delete this.onEnterFrame;
  }
};
MovieClip.prototype.fadeOut = function(minFade, speed) {
  this._alpha -= speed;
  if (this._alpha<=minFade) {
   this._alpha = minFade;
   delete this.onEnterFrame;
  }
};
invisBDown.onRollOver = function() {
  fadeUp.onEnterFrame = function() {
   this.fadeOut(0, 10);
  };
};
invisBDown.onRollOut = function() {
  fadeUp.onEnterFrame = function() {
   this.fadeIn(100, 10);
  };
};
  1. MovieClip.prototype.fadeIn = function(maxFade, speed2) {
  2.   this._alpha += speed2;
  3.   if (this._alpha == maxFade) {
  4.    this._alpha = maxFade;
  5.    delete this.onEnterFrame;
  6.   }
  7. };
  8. MovieClip.prototype.fadeOut = function(minFade, speed) {
  9.   this._alpha -= speed;
  10.   if (this._alpha<=minFade) {
  11.    this._alpha = minFade;
  12.    delete this.onEnterFrame;
  13.   }
  14. };
  15. invisBDown.onRollOver = function() {
  16.   fadeUp.onEnterFrame = function() {
  17.    this.fadeOut(0, 10);
  18.   };
  19. };
  20. invisBDown.onRollOut = function() {
  21.   fadeUp.onEnterFrame = function() {
  22.    this.fadeIn(100, 10);
  23.   };
  24. };



This bit of code is obviously specific to the "down" movieClip (the object names are different for the "up" movieClip...that is all).

This is all fine and dandy, but, the following happens:

1) when you rollOver the up movieClip it does its fade-out/fade-in spectacle,
2) when you rollOver the down movieClip it does its fade-out/fade-in spectacle,
3) now the problem comes up...you go and rollOver the up movieClip again and nothing happens for a long time, then all of a sudden it fades out like it's supposed to...what's with the delay?...

The file I am working with is here: http://www.afastudios.com/vita.zip

Thanks,

tykomusic

Post Information

  • Total Posts in this topic: 11 posts
  • Users browsing this forum: No registered users and 15 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.