dcsimg
A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: quick onEnterFrame question

  1. #1
    Senior Member frostbite's Avatar
    Join Date
    Aug 2003
    Location
    Colorado
    Posts
    666

    onEnterFrame question - please help!

    Updated - Read my post below
    Last edited by frostbite; 01-26-2007 at 02:46 PM.
    Yarrg Matey!

  2. #2
    Member
    Join Date
    Jan 2007
    Posts
    68
    why don't u use a function and then attach it to the places u want it to work?
    that way it'll call out when its needed.

  3. #3
    Senior Member frostbite's Avatar
    Join Date
    Aug 2003
    Location
    Colorado
    Posts
    666
    that would definitely make it easier but I think the problem could still arise if the function has onEnterFrame in it...
    Yarrg Matey!

  4. #4
    Senior Member frostbite's Avatar
    Join Date
    Aug 2003
    Location
    Colorado
    Posts
    666
    Code:
    var menuOver:Function = function(mc_blank:MovieClip):Void {
        // function block here
        
    	mc_blank.gotoAndPlay(2);
    	var theArray:Array ;
    	theArray = new Array(30) ;
    
    	var theCircle:MovieClip ;
    
    	var maxYV = 30 ;
    	c1yv = new Array(maxYV) ;
    	for (var z:Number = 0 ; z < maxYV ; z++) {
    		c1yv[z] = ( Math.random() * 3 ) + 1 ;
    	}
    
    
    	for (var a:Number = 0 ; a < 30 ; a++) {
    		theCircle = attachMovie("circle","circle"+_root.getNextHighestDepth(), a+_root.getNextHighestDepth()) ;
    		var randSize:Number = Math.random() * 30 ;
    		theCircle._xscale = randSize ;
    		theCircle._yscale = randSize ;
    		theCircle._x = Math.random() * (mc_blank._width + 40) + (mc_blank._x - 20);
    		theCircle._y = -1 * (Math.random() * ( 30)) ;
    		theArray[a] = theCircle ;
    	}
    	
    	mc_blank.onEnterFrame = function() {
    	
    	for (var a:Number = 0 ; a < 30 ; a++) {
    	    theArray[a]._y += c1yv[a] ;
    		if ( theArray[a]._y > 30 ) {
    			theArray[a]._y = 0 ;
    		}
    	}
    	
    	}
    	
    	return;
    }
    var menuOut:Function = function(mc_blank:MovieClip):Void {
    	//function block here
    	
    	mc_blank.gotoAndPlay(6);
    	
    	mc_blank.onEnterFrame = function () {
    		for (var a:Number = 0 ; a < 30 ; a++) {
    			theArray[a]._y += c1yv[a] ;
    			if ( theArray[a]._y > 30 ) {
    				theArray[a]._y = 0 ;
    			}
    		    theArray[a]._alpha -= 10;
    		}
    	}
    	
    	return;
    }

    That is the code I have defining the functions

    The code calling the functions are on the buttons and look like this.

    Code:
    on(rollOver) {
    	menuOver(mc_home);
    }
    on(rollOut) {
    	menuOut(mc_home);
    }
    Here is the problem, for one, the onEnterFrame of the menuOut function does not make the circles fade away, but when all that code was just on the buttons themselves it did.

    The other problem is that even if they did rollOut, when you would rollOver another button when one is still fading out, it would just cancel the rollOut and create the array on the other button starting that animation.
    Yarrg Matey!

  5. #5
    Member
    Join Date
    Jan 2007
    Posts
    68
    oh use the delete syntax..

    on(rollOut){
    menuOut(mc_home)
    delete MC.onEnterFrame
    }

    target the previous one so that it cuts out the loop.

  6. #6
    Senior Member frostbite's Avatar
    Join Date
    Aug 2003
    Location
    Colorado
    Posts
    666

    Getting Warmer...

    Well it is getting there.
    Code:
    var theArray:Array ;
    theArray = new Array(50) ;
    
    var theCircle:MovieClip ;
    
    var maxYV = 50 ;
    c1yv = new Array(maxYV) ;
    for (var z:Number = 0 ; z < maxYV ; z++) {
    	c1yv[z] = ( Math.random() * 3 ) + 1 ;
    }
    	
    var menuOver:Function = function(mc_blank:MovieClip):Void {
    
    	mc_blank.gotoAndPlay(2);
    	
    	for (var a:Number = 0 ; a < 50 ; a++) {
    		theCircle = attachMovie("circle","circle"+_root.getNextHighestDepth(), a+_root.getNextHighestDepth()) ;
    		var randSize:Number = Math.random() * 30 ;
    		theCircle._xscale = randSize ;
    		theCircle._yscale = randSize ;
    		theCircle._x = Math.random() * (mc_blank._width + 40) + (mc_blank._x - 20);
    		theCircle._y = -1 * (Math.random() * ( 30)) ;
    		theArray[a] = theCircle ;
    	}
    
    	mc_blank.onEnterFrame = function() {
    	
    	for (var a:Number = 0 ; a < 50 ; a++) {
    	    theArray[a]._y += c1yv[a] ;
    		if ( theArray[a]._y > 30 ) {
    			theArray[a]._y = 0 ;
    		}
    	}
    	
    	}
    	
    	return;
    }
    
    var menuOut:Function = function(mc_blank:MovieClip):Void {
    	//function block here
    	
    	mc_blank.gotoAndPlay(6);
    	
    	mc_blank.onEnterFrame = function () {
    		for (var a:Number = 0 ; a < 50 ; a++) {
    			theArray[a]._y += c1yv[a] ;
    			if ( theArray[a]._y > 30 ) {
    				theArray[a]._y = 0 ;
    			}
    		    theArray[a]._alpha -= 10;
    			if ( theArray[a]._alpha = 0 ) {
    				delete mc_blank.onEnterFrame;
    			}
    		}
    	}
    	
    	
    	return;
    }
    Basically why it wasn't fading out before was a scope issue, I was initializing the array within the rollover function.

    and I added the delete mc_blank.onEnterFrame within the rollout so when it is finished fading out, it deletes the onEnterFrame, and not beforehand.

    The only problem now, however, is if you rollover another of the buttons while the menuOut function is still fading out the array, the the array that is fading out will be deleted and the other button will just fade out the array and stop.

    How can I get it so it avoids this problem, so if you roll over another button, the rollout on the previous button finishes?
    Yarrg Matey!

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