-
Script for button to fade in...
Hi, i am used to tweening to make buttons fade in, but how you do this using scripting that can be assigned to each button?
Many thanks, Poly
-
Senior Member
Fade out:
instanceName._alpha -= 5; //Higher than 5 = faster, lower = slower.
Fade in:
instanceName._alpha += 5;
_alpha controls the alpha (opacity) property of the object.
-
thanks, excuse my newbieness but what handler does this need to go in? i'm guessing its something like onClipEvent(load)... but keep getting errors
also, how can a delay be assign to the fade in??
many thanks
-
Flash/Flex Developer
You would use a combination of setInterval (to provide the delay) and Tween in a function to complete full animation. The initial function would go under which ever element you want to cast the initial event.
Everything else would fall under a separate method.
Some people are like Slinkies, not really good for anything, but they bring a smile to your face when pushed down the stairs.
-
-
Flash/Flex Developer
Sixtyacura, Are you helping with the issue, or just trying to advertise for your site?
Some people are like Slinkies, not really good for anything, but they bring a smile to your face when pushed down the stairs.
-
my code for the movie (acting like a button) is
onClipEvent (load) {
MovieClip.prototype.Increment = function(maxAlpha, speed) {
this.onEnterFrame = function() {
this._alpha += speed;
if (this._alpha>=maxAlpha) {
this._alpha = maxAlpha;
delete this.onEnterFrame;
}
};
};
with ("thumb0") {
_alpha = 0;
Increment(60,8);}
}
I've tried adding the setInterval command at the end but no luck
where would the setInterval need to go?? and what is the functionName it requires? i'm guessing it would be 'Increment'.
-
Flash/Flex Developer
Using SetInterval
First, I'm going to assume you've created a new instance of the Increment class, otherwise your button wouldn't fade in. For more info on prototypes try here
I changed the code a little which is excluding your prototype. Modify my version to work for your situation.
Code:
//On Main timeline not within a button or clip
var intervalID:Number;
function incrementMe(obj, max, speed)
{
obj._alpha += speed;
if (obj._alpha>=maxAlpha) {
obj._alpha = maxAlpha;
clearInterval(intervalID);
}
}
//When the button is released, then it will start the entire cycle.
thumb0.onRelease = function()
{
clearInterval(intervalID);
this._alpha = 0;
intervalID = setInterval(incrementMe, 100, this, 60, 8);
}
I didn't instantiate my button with the prototype, so I excluded it. I have a function that does nothing but increases the alpha of a specific obj to the maximum available for that object. This code can be added to the class used when the button was instantiate, and the name of the function would be called then (ie. thumb0.increaseMe().
With in my if state of the increase function, I have a clearInterval. This stops the repeating call to incrementMe.
I place the calling function within the button. When the button is released, it changes it alpha to zero, and start the interval calling the incrementMe function, at 100 milliseconds intervals and passing the other necessary parameters (whos calling, max alpha, and speed).
Does that help?
Some people are like Slinkies, not really good for anything, but they bring a smile to your face when pushed down the stairs.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|