11113
March 22, 2006, 3:51am
1
Here is my code, i’ve tried searching the forums and fighting with this way of fading the movie clip in and out. The movie clip has an instance name of “box”:hitman:, my brother also can’t figure it out. need help!
[COLOR=Blue]var[/COLOR] fadeChecker:[COLOR=Blue]Boolean[/COLOR] = [COLOR=Blue]true[/COLOR];
[COLOR=Blue]function[/COLOR] flicker():[COLOR=Blue]Void[/COLOR]{
[COLOR=Blue]if[/COLOR](box.[COLOR=Blue]_alpha[/COLOR] >= 100){
fadeChecker = [COLOR=Blue]true[/COLOR];
}
[COLOR=Blue]else if[/COLOR](box.[COLOR=Blue]_alpha[/COLOR] <= 0){
fadeChecker = [COLOR=Blue]false[/COLOR];
}
[COLOR=Blue] if[/COLOR](fadeChecker == [COLOR=Blue]true[/COLOR]){
box.[COLOR=Blue]_alpha--[/COLOR];
}
[COLOR=Blue]else if[/COLOR](fadeChecker == [COLOR=Blue]false[/COLOR]){
box.[COLOR=Blue]_alpha[/COLOR]++;
}
}
[COLOR=Blue]var [/COLOR]nInterval:[COLOR=Blue]Number[/COLOR] = [COLOR=Blue]setInterval[/COLOR](flicker,1000);
11113
March 22, 2006, 4:22pm
2
I got it working, the [COLOR=“Blue”]setInterval[/COLOR] was just too slow, it went put opacity down by 1% each second, that’s pretty slow.
Now that i have that solved. I would like to know if there is an easier way to fade out these images all from the same function. As you can tell, this function only works for one movieclip at a time.
i would proably use the tween class on your previous code, It will gave a much better fade, plus you can use easing too:)
11113
March 24, 2006, 3:59pm
5
Wow, that sounds interesting, there’s a tween class in actionscript? you can ease through script too! Can you elaborate!
I’ve got two options for you:
easing function:
mx.transitions.OnEnterFrameBeacon.init();
MovieClip.prototype.setOEFBD = function():Boolean {
if (!this.__OEFBD) {
this.__OEFBD = new Object();
MovieClip.addListener(this.__OEFBD);
this.__OEFBD._parent = this;
AsBroadcaster.initialize(this.__OEFBD);
this.__OEFBD.addListener(this);
return true;
}
return false;
};
MovieClip.prototype.easeTo = function(p:String, t:Number, e:Number):Void {
this.setOEFBD();
this.__OEFBD.onEnterFrame = function():Void {
this._parent[p] += (t - this._parent[p]) / e;
if (Math.round(this._parent[p]) == t) {
this.broadcastMessage("onEaseFinished");
delete this.onEnterFrame;
}
};
};
usage:
//MovieClip.easeTo(property:String, target:Number, ease:Number):Void
mc.easeTo("_alpha", 0, 10);
easing function:
_global.Tween = mx.transitions.Tween;
MovieClip.prototype.easeTo = function(p:String, t:Number, d:Number):Void {
new Tween(this, p, mx.transitions.easing.Regular.easeOut, this[p], t, d, false).onMotionFinished = function():Void {
this.obj.onMotionFinished();
};
};
usage:
//MovieClip.easeTo(property:String, target:Number, duration:Number):Void
mc.easeTo("_alpha", 0, 30);
The first one has a lot of extra code in it that may not be of use to you at this point in time, it’s basically the long form of the second one :hoser: