A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: Need script to randomly fade mcs?

Hybrid View

  1. #1
    Senior Member Jaffasoft's Avatar
    Join Date
    Apr 2001
    Location
    On Travel
    Posts
    1,588
    I wrote this so far can anyone help with a better way i should have done this:

    There is just six mcs on stage with a pic in each and named from 'mc6' though to 'mc11'

    chechMc = setInterval(nextMC,500);
    fadeturn=true;
    myRandomMcs = new Array(6, 7, 8, 9, 10, 11);
    function nextMc() {
    nextMcToFade = myRandomMcs.splice(random(myRandomMcs.length), 1);
    trace(["mc_"+nextMcToFade]);
    fadeClips();
    if (nextMcToFade.length == isNaN(0)) {
    trace("Empty array");
    //this is where I need the alternating tricker each time to set fadeturn true or false
    myRandomMcs.push(6, 7, 8, 9, 10, 11);
    nextMcToFade = myRandomMcs.splice(random(myRandomMcs.length), 1);
    }
    }
    MovieClip.prototype.fadeClips = function() {
    this.onEnterFrame = function() {
    if (fadeturn=true) {
    //do fade up
    this["mc_"+nextMcToFade]._alpha += 3;
    }
    if (fadeturn=false) {
    this["mc_"+nextMcToFade]._alpha -= 3;
    }
    };
    };
    Last edited by Jaffasoft; 07-13-2006 at 09:39 AM.

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    PHP Code:
    chechMc setInterval (nextMC500);
    fadeturn false;
    myRandomMcs = new Array (67891011);
    function 
    nextMc ()
    {
        
    nextMcToFade myRandomMcs.splice (random (myRandomMcs.length), 1);
        
    trace (["mc_" nextMcToFade]);
        var 
    myMc:String "mc_" nextMcToFade;
        
    fadeClips (myMc);
        if (
    nextMcToFade.length == isNaN (0))
        {
            
    trace ("Empty array");
            
    //this is where I need the alternating tricker each time to set fadeturn true or false
            
    myRandomMcs.push (67891011);
            
    nextMcToFade myRandomMcs.splice (random (myRandomMcs.length), 1);
        }
    }
    function 
    fadeClips (myMc)
    {
        var 
    mc:MovieClip = eval (myMc);
        
    this.onEnterFrame = function ()
        {
            if (
    fadeturn == true)
            {
                
    //do fade up
                
    mc._alpha += 3;
            }
            if (
    fadeturn == false)
            {
                
    mc._alpha -= 3;
                if (
    mc._alpha <= 0)
                {
                    
    delete this.onEnterFrame;
                    
    nextMc ();
                }
            }
        };
    }
    nextMc (); 
    - The right of the People to create Flash movies shall not be infringed. -

  3. #3
    Senior Member Jaffasoft's Avatar
    Join Date
    Apr 2001
    Location
    On Travel
    Posts
    1,588
    Ok you've posted yours and i was just about to post where i was up to. This almost working. Is eval depreciated?

    But know it needs to be condensed down but cant work out how??

    Code:
    myRandomMcsUp = new Array(6, 7, 8, 9, 10, 11);
    MovieClip.prototype.nextMc = function() {
    	nextMcToFade = myRandomMcsUp.splice(random(myRandomMcsUp.length), 1);
    	fadeClips();
    	if (nextMcToFade.length == isNaN(0)) {
    		trace("Finished fading up will now begin fade down");
    		myRandomMcsUp.push(6, 7, 8, 9, 10, 11);
    		nextMcToFade = myRandomMcsUp.splice(random(myRandomMcsUp.length), 1);
    		nextMcDown();
    	}
    	trace(["mc_"+nextMcToFade]);
    };
    MovieClip.prototype.fadeClips = function() {
    	this.onEnterFrame = function() {
    		this["mc_"+nextMcToFade]._alpha += 5;
    		if (this["mc_"+nextMcToFade]._alpha>=100) {
    			
    			nextMc();
    		}
    	};
    };
    MovieClip.prototype.nextMcDown = function() {
    	nextMcToFade = myRandomMcsUp.splice(random(myRandomMcsUp.length), 1);
    	fadeClipsDown();
    	if (nextMcToFade.length == isNaN(0)) {
    		myRandomMcsUp.push(6, 7, 8, 9, 10, 11);
    		nextMcToFade = myRandomMcsUp.splice(random(myRandomMcsUp.length), 1);
    		nextMc();
    		trace("Finished fading down will now begin fade down");
    	}
    	trace(["mc_"+nextMcToFade]);
    };
    MovieClip.prototype.fadeClipsDown = function() {
    	this.onEnterFrame = function() {
    		this["mc_"+nextMcToFade]._alpha -= 5;
    		if (this["mc_"+nextMcToFade]._alpha<=0) {
    			nextMcDown();
    		}
    	};
    };
    Last edited by Jaffasoft; 07-13-2006 at 09:50 AM.

  4. #4
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    I don't know your lower script but you can also change the two lines to this:

    var myMc:MovieClip = this["mc_" + nextMcToFade];

    var mc:MovieClip = myMc;

    if you don't like eval.
    - The right of the People to create Flash movies shall not be infringed. -

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