A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: Alpha and Functions :(

  1. #1
    Owner of the ™ thread tublu's Avatar
    Join Date
    Nov 2000
    Posts
    2,430
    Hi guys , this is for a friend . Please help me help him out

    ok ... here's the scenario
    I have a movie Clip on stage named M whose alpha I will be playing with . The basic idea is at load I will be decreasing it by decrements of 5 . But whe it reaches a minimum , I want to create a function which will increase it again by +5 . Simmilarily another function to check wether it has reached a Maximum , and if so , then again start decreasing by -5 . That is the basic logic .
    On frame 1 , I have
    Code:
    low = 5;
    high = 95;
    function incr () {
    	if (_root.m._alpha<=low) {
    		do {
    			_root.m._alpha +=5;
    		} while (_root.m._alpha ==high);
    	}
    }
    Frame # 2 :
    Code:
    _root.m._alpha -=5;
    			incr();
    Frame 3 :
    Code:
    gotoAndPlay (2);
    ..... Now the obvious problem , that am facing is ( this is only half of the code ... just the increasing aprt ...I have not yet written the decr() function ) ... as I run this , the frame #3 runs perfect and I think the incr() function is ok too . BUt what is creating the problem is in frame 3 there is a gotoAndPlay(2) which is overruling the incr() function as soon as it is tryuing tio get executed and hence the alpha increment is never shown The decrease that is being forced is overriding the implenmentation of the incr() function .
    How can i skip this ?

  2. #2
    Owner of the ™ thread tublu's Avatar
    Join Date
    Nov 2000
    Posts
    2,430
    bump ..... anyone ??

  3. #3
    Senior Member catbert303's Avatar
    Join Date
    Aug 2001
    Location
    uk
    Posts
    11,222
    Hi,

    maybe you could try this...

    on the movie clip as a clipevent set the initial alpha value to be the same as your high value;

    onClipEvent(load) {
    this._alpha = _root.high;
    }

    then frame 1 (of main time line)

    direction = -1; // we start by decreasing the alpha value
    high = 95;
    alpha = high;
    low = 5;

    frame 2...

    alpha += 5 * direction;
    _root.m._alpha = alpha;

    if (alpha == high || alpha == low) {
    direction *= -1; // if it reaches maximum or minimum alpha change direction
    }

    frame 3...

    gotoAndPlay(2);

  4. #4
    Senior Member
    Join Date
    Jun 2001
    Location
    las vegas,nv
    Posts
    694
    Try this prototype and clip code. I just tested it and it works fine. I think it may be what you want.

    Movieclip.prototype.fade=function(){
    var maxAlpha=100;
    var minAlpha=0;
    if(_alpha<maxAlpha&&up==0){
    _alpha+=5;
    }else{
    up=1;
    }
    if(up){
    if(_alpha>minAlpha){
    _alpha-=5;
    }else{
    up=0;
    _alpha+=5;
    }
    }
    }

    onClipEvent(load){
    up=0;
    }


    onClipEvent(enterFrame){
    fade();
    }
    [Edited by dzlpwr on 05-23-2002 at 10:32 PM]

  5. #5
    Flash Honkie
    Join Date
    Nov 2001
    Location
    Athens, Ga
    Posts
    212

    easier way, possibly?

    Okay this might be even easier than that.

    set a variable someone, a, to be 1 (1 or 0);

    if (a==1){
    mymovie._alpha -=5;
    if(myovie._alpha == 5){
    a=0;}
    }

    if (a==0){
    mymovie._alpha +=5;
    if(myovie._alpha == 100){
    a=1;}
    }

    so, it just alternates between the functions depending on whether or not a is true or false, or 1 or 0, whatever.

    lemme know if that works


  6. #6
    Owner of the ™ thread tublu's Avatar
    Join Date
    Nov 2000
    Posts
    2,430
    thanx guys .. will post back , if it works

  7. #7
    Flash Honkie
    Join Date
    Nov 2001
    Location
    Athens, Ga
    Posts
    212

    gravy

    okay, ignore the myovie, and replace with mymovie...cheese and rice

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center