View Full Version : alpha tween in actionscript
Vikana
03-09-2005, 06:38 PM
Hi
I am trying to create an alpha tween in actionscript
I have created the mc and asked it to go through a loop adding to the alpha at every increment.
I manage to get it to go through the loop, but it is not changing the alpha value.
_root.createEmptyMovieClip( "tween", 1 );
with ( _root.tween )
{
lineStyle( 20, 0xff00ff, 10 );
moveTo( 0, 0 );
lineTo( 100,0);
}
fadeUp = function(){
temp = false
while(temp != true){
for(i>=0; i<100; i++){
trace("has this gone through loop");
_root.tween._alpha++;
}
temp = true;
}
}
fadeUp();
Once I get the fadeup working, I will then create another loop for the fadeDown.
Any ideas on what I am doing wrong
Cheers
Vikana :cool:
O = _root.createEmptyMovieClip("tween", 1);
with (_root.tween) {
//i change the Alpha of the line it will also work whit a lover one
//BUT expect NOT that this line will by SOLID when you set the alpha of the movie clip to 100
//if you set the Alpha of the MC to 100 the alpha of this line will by to what ever you set it
//let's say "20"
//so woud you set the alpha of the MC to 50
//the resulting alpha of the LINE woud by 10 !!!!
//i dont think you can set (change) the alpha of a line afterwards
lineStyle(20, 0xff00ff, 100);
moveTo(0, 0);
lineTo(100, 0);
}
O._alpha = 0;
fadeUp = function () {
_root.tween._alpha++;
if (_root.tween._alpha>=100) {
trace("INTERVAL CLEARED")
clearInterval(IntVal);
}
};
//setInterval is returning a number it's countinous counted up ward (warning BAD english)
//so IntVal will have the ID "1" next line woud you execute a setinterval somewhere else
//it's return woud by 2 then next time 3 and so on ...
//whit this ID you can stop the interval
//setinterval is executing the function after each "100" milliseconds (in this case coud by any number)
IntVal = setInterval(fadeUp, 100);
//as you had it
//the hole loop is executed on ONE frame so you woudnt see any tween at all because
//frames are redrawen each frame
//but the hole loop is just ONE frame
//other option is to use onEnterFrame
//BY CAREFULY WGIT BOTH TO STOP THEM AFTER YOU NOT NEED THEM
//outher it will cause performace problems
//AND it will by a nightmare to find the problem
mdeligt
03-11-2005, 09:19 AM
}onClipEvent(enterFrame){
if(this._alpha < 100) this._alpha += 1;
}
Once I get the fadeup working, I will then create another loop for the fadeDown.
This line got me thinking....Why? Lots of us do it, but with a little (and it doesnt get much less) Math we can avoid having a fadeOut and a fadeIn function . This is it, I chose to do without and if statements, because that is something I try to do at the moment.
function changeAlpha (target, speed) {
target.onEnterFrame = function () {
return ((target._alpha <= 100) && (target._alpha >= 0)) ? target._alpha += speed : assign (target);
};
function assign (target) {
target.onEnterFrame = null;
return (target._alpha < 0) ? target._alpha = 0 : target._alpha = 100;
}
}
//USAGE
//set a speed we want to use to fade in
speed = 10;
_root.orange.onRelease = function () {
//invert the speed for example from 10 to -10
//thus making our button toggle on or off
speed = -speed;
changeAlpha (this, speed);
};
Any ideas on how to reduce it some more?
Taff
Vikana
03-13-2005, 08:20 AM
I would like to thank you guys for the quick response.
I shall come here more often
Respect
Vikana :cool:
Vikana
05-10-2005, 08:27 PM
hi guys
came up with another solution (managed to get some time to play with it)
_root.attachMovie("ballMc","ballMc",0,{_x:100, _y:100});
ballMc._alpha =0;
fadeUpProc = function(){
temp = false;
if(temp != true){
fadeUp = function(){
if(ballMc._alpha<=100){
ballMc._alpha++;
updateAfterEvent();
}else{
clearInterval(upInterval);
fadeDownProc();
temp = true;
}
}
upInterval = setInterval(fadeUp,1);
}
}
fadeDownProc = function(){
temp = false;
if(temp != true){
fadeDown = function(){
if(ballMc._alpha>=0){
ballMc._alpha--;
updateAfterEvent();
}else{
clearInterval(downInterval);
fadeUpProc();
temp = true;
}
}
downInterval = setInterval(fadeDown,1);
}
}
fadeUpProc();
cheers for the help
Vikana :cool:
senocular
05-10-2005, 08:58 PM
[useastags]
.
Vikana
05-12-2005, 11:37 AM
Thanks for the tip
Adjusted code as requested
Vikana :cool:
vBulletin® v3.7.1, Copyright ©2000-2009, Jelsoft Enterprises Ltd.