A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Function in a Function

  1. #1
    Senior Member Gloo pot's Avatar
    Join Date
    Aug 2005
    Location
    Australia Mate!
    Posts
    874

    Function in a Function

    I have this peice of code and all of it works except the bolded part, i cant figure out why, i thought it might have somthing to do with it being inside another function.
    Code:
    function RunBubble() {
    	var i;
    	for (i=0; i<BubbleCount; i++) {
    		if (_root.BubbleArray[i] == 1) {
    			if (_root["BubbleArray"+i].num == 1) {
    				_root["BubbleArray"+i]._y -= 5;
    				if (_root["BubbleArray"+i]._y<-10) {
    					_root["BubbleArray"+i].removeMovieClip();
    					_root.BubbleArray[i] = 0;
    				}
    				_root["BubbleArray"+i].onRollOver = function() {
    					_root["BubbleArray"+i].removeMovieClip();
    					_root.BubbleArray[i] = 0;
    				};
    			}
    		}
    	}
    }
    I know all the other stuff works because the bubbles move upwards and are removed at the top of the stage.
    92.7 Fresh FM for all your South Aussies - Doof Doof music FTW people!

  2. #2
    Hype over content... Squize's Avatar
    Join Date
    Apr 2001
    Location
    Lost forever in a happy crowd...
    Posts
    5,926
    You can drop functions within functions ( I'm forever chaining onEnterFrames for quick and dirty fades ).

    Not sure why your code isn't working, but you don't need to add the rollOver in a loop like that. When you first create your sprite just add the rollOver code then, rather than adding it every time you move each sprite.

    Squize.

  3. #3
    avatar free
    Join Date
    Jul 2002
    Location
    UK
    Posts
    835
    It's because the loop variable i does not exist inside the instance onRollOver scope, only in the RunBubble function scope.

    I think you could attach vars, like _root["BubbleArray"+i].id = i; and then reference them later inside onRollOver with _root["BubbleArray"+this.id] = 0; Been a while since i've done this though, so not 100% sure on that
    jonmack
    flash racer blog - advanced arcade racer development blog

  4. #4
    Senior Member
    Join Date
    Jun 2005
    Posts
    203
    put the rollover action on the initial movie clip that you' copied.
    Tsehehehehehe

  5. #5
    Senior Member Gloo pot's Avatar
    Join Date
    Aug 2005
    Location
    Australia Mate!
    Posts
    874
    Its kewl i spent an hour or so looking at the situation and i just decided to hittest my mouse to _root.BubbleArray[i] which works wonders ..

    Thanks any way people
    92.7 Fresh FM for all your South Aussies - Doof Doof music FTW people!

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