A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: Random Position With Alpha Fade

  1. #1
    Senior Member
    Join Date
    May 2003
    Posts
    160

    Random Position With Alpha Fade

    i am trying to make a leaf movie clip fly in from the left side of the screen and fade away as it reaches the right side. it's start _x and _y position is randomized.

    i would also like the leaf movie clip duplicate itself when it a certain _x value and have it's alpha fade to 0%.

    psuedo code (what else i want to happen):

    when mc._x= 350
    --duplicate leaf movie clip at random _x & _y position on left side of screen.
    --mc alpha fades out to 0%.

    if you need a test file, i can post one, thanks.
    Last edited by addamtron; 01-05-2004 at 12:41 AM.

  2. #2
    Senior Member
    Join Date
    Jun 2002
    Location
    Toronto, Canada
    Posts
    305
    RE-read your post, it actually makes no sense.. But here what i got out of it.
    Code:
    i=1;
    makeBall=function(){
      _root.attachMovie("ball", "ball"+i, i);
      _root["ball"+i]._x=random(300);
      _root["ball"+i]._y=random(200);  
      _root["ball"+i].onEnterFrame=moveMc();
      i++;
    
    }
    moveMc=function(){
      this._x+=5;
      if(this._x>=someValue){
        makeBall();
        this.onEnterFrame=fadeThis();
      }
    }
    fadeThis=function(){
      this._alpha-=10;
      if(this._alpha<=0){
         this.removeMovieClip();
       }
    }
    
    makeBall();
    Hope that this makes sense
    Last edited by untitledskate; 01-05-2004 at 12:30 AM.

  3. #3
    Senior Member
    Join Date
    May 2003
    Posts
    160
    here is a test file i am working with.

    there is code on the leaf image, on the 1st frame and in the blank movie clip on the stage.

    the leaf follows randomized sine wave patterns to give it movement across the stage. when the leaf reaches the end of it's sine wave it disappears. what i want it to do is fade out, not just disappear all the sudden.

    thanks.
    Last edited by addamtron; 01-05-2004 at 04:29 PM.

  4. #4
    Senior Member
    Join Date
    Jun 2002
    Location
    Toronto, Canada
    Posts
    305
    my code doesnt make it disappear all of a sudden... I wrote a function called "fadeThis" that fades it out by 10 alpha every frame until its invisable.... Read my code again

  5. #5
    Senior Member
    Join Date
    May 2003
    Posts
    160
    ya i had tried that before and it worked, but when the leaf duplicated it was invisible.

    also the way i'm doing it isn't using attachMovie, do you think this is the best way to go about it?

    thanks for the help.

  6. #6
    Senior Member
    Join Date
    May 2003
    Posts
    160
    also i got this error when i tried your code:

    256 levels of recursion were exceeded in one action list.
    This is probably an infinite loop.
    Further execution of actions has been disabled in this movie.

    can you look at my test file and see what's wrong.
    Attached Files Attached Files

  7. #7
    Senior Member
    Join Date
    Jun 2002
    Location
    Toronto, Canada
    Posts
    305
    Hey man, me again.. Yeah, my apologise.. I had a typo that I didnt notice until after i re-wrote it. Heres another way to do it.. but its a little messy. I opened ur fla and noticed u put all the code on the MC. Please dont. All you need is 1 frame.. 1 layer. and the following all on the layer
    Code:
    i=2;
    speed=10;
    attachMovie("ball", "ball1", 1);
    ball1._y=random(200);
    movieClip.prototype.move=function(){
    	this._x+=speed;
    	if(this._x>400){
    		_root.attachMovie("ball", "ball"+i, i);
    		_root["ball"+i]._y=random(400);
    		_root["ball"+i]._x=0;
    		_root["ball"+i].onEnterFrame=function(){
    			this.move();
    		}
    		_root.i++;
    		this.onEnterFrame=function(){
    			this._x+=speed;
    			this._alpha-=10;
    			if(this._alpha<0){
    				this._alpha=100;
    				this.removeMovieClip();
    			}
    		}
    	}
    }
    ball1.onEnterFrame=function(){
    	this.move();
    }
    Now in your library, under linkage.. make sure that it is labeled 'ball' and toggle, export on first frame and export for actionscript. This does work.. i tried it myself

    Cheers and sorry for the mess up

  8. #8
    Senior Member
    Join Date
    May 2003
    Posts
    160
    thanks alot, that's just how i imagined it! now i just got to add it to my other script and i'm good to go. thanks again. i haven't used the linkage really until now, is this the kind of instance whre it is most often used?

  9. #9
    Senior Member
    Join Date
    Jun 2002
    Location
    Toronto, Canada
    Posts
    305
    well, I use linkage for everything really. I try to avoid manually bringing things onto the stage because it really limits what you can do sometimes. Like, if you need 100 buttons to do something.. it seems kinda ridiculous to click and drag 100 times... but if you use actions, its like 10 lines long..

    It just allows more future flexibility

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