A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: Bubbles - duplicate problems

  1. #1
    Member
    Join Date
    Jun 2004
    Posts
    83

    Bubbles - duplicate problems

    Hi!

    I'm working on a application with some bubbles. Each bubble goes from the bottom to the top. It works just fine with just one bubble, but when I duplicate the bubble it just stops on it's way towards the top. I want to have many of them, with different properties.

    Could there be a "level" problem or?

    Here's the code:

    Code:
    function createBubble(){
    	i++;
    	scale = random(120) + 30;
    	xMove = random(10)+1;
    	yMove = random(30)+1;
    	bubble = bubble_mc.duplicateMovieClip("bub" + i, i);
    	bubble._xscale = scale;
    	bubble._yscale = scale;
    }
    
    my_btn.onPress = function(){
         //myBubble = setInterval(createBubble, random(3000) + 100);
        createBubble();
    }
    
    this.onEnterFrame = function() {
    	
    		bubble._y -= yMove;		
    		bubble._x = Math.sin(a) * xMove + 150;
    		a += 0.2;
    
    		
    		if(bubble._xscale > 0){
    			bubble._xscale -= scaleFactor;
    			bubble._yscale -= scaleFactor;
    		}
    		
    		if(bubble._y < 0){
    			removeMovieClip(bubble);
    			createBubble();
    		}
    
    	
    }
    Thankful for some advice
    /S-fish
    Last edited by swordfish123; 02-08-2007 at 02:28 PM.

  2. #2
    Junior Member
    Join Date
    Apr 2004
    Location
    New Jersey
    Posts
    28
    can you post the fla?

  3. #3
    Member
    Join Date
    Jun 2004
    Posts
    83
    Here it comes...
    Attached Files Attached Files

  4. #4
    Junior Member
    Join Date
    Apr 2004
    Location
    New Jersey
    Posts
    28
    I think I got it mostly....here take a look....unfortunately i gotta run but here is the code.

    Code:
    stop();
    
    i = 0;
    a = 0.15;
    scaleFactor = 0.5;
    bubble_mc._visible = 0;
    
    function createBubble(){
    	i++;
    	scale = random(120) + 30;
    	xMove = random(10)+i;
    	yMove = random(30)+i;
    	duplicateMovieClip("bubble_mc", "bub" + i, i);
    	trace(this["bub" + i]._name);
    	this["bub" + i]._y = 450;
    	this["bub" + i]._xscale = scale;
    	this["bub" + i]._yscale = scale;
    	
    	this["bub" + i].onEnterFrame = function() {
    	
    		this._y -= yMove;		
    		this._x = Math.sin(a) * xMove + 150;
    		a += 0.2;
    
    		if(this._xscale > 0){
    			this._xscale -= scaleFactor;
    			this._yscale -= scaleFactor;
    		}
    		
    		if(this._y < 0){
    			this.swapDepths();
    			removeMovieClip(this);
    			//createBubble();
    		}
    
    	
    }
    }
    
    my_btn.onPress = function(){
    //myBubble = setInterval(createBubble, random(3000) + 100);
    createBubble();
    
    }

  5. #5
    Member
    Join Date
    Jun 2004
    Posts
    83
    Thanx, but not exactly what I looking after...if you hit the button 10 times fast, we got a quite strange movement

    You can check the attachment (only got the .swf-file), but this is the movemet I want. Many bubbles at the same time, and each of them with it's own property..
    Attached Files Attached Files

  6. #6
    :
    Join Date
    Dec 2002
    Posts
    3,518

    Or maybe try something like this...

    Code:
    stop();
    var i = 0;
    var a = 0.15;
    var scaleFactor = 0.5;
    var intID = "";
    bubble_mc._visible = 0;
    var stopped = true;
    //
    function getRand(maxNum, minNum) {
    	return Math.floor(Math.random() * (maxNum - minNum)) + minNum;
    }
    function createBubble() {
    	clearInterval(intID)
    	if (!stopped){
    		intID = setInterval(createBubble, getRand(2000, 100))
    	}
    	i++;
    	bubble = bubble_mc.duplicateMovieClip("bub" + i, i);
    	bubble.scale = getRand(120, 30);
    	bubble._xscale = scale;
    	bubble._yscale = scale;
    	bubble.xMove = getRand(10, 1);
    	bubble.yMove = getRand(30, 1);
    	bubble.a = a;
    	bubble.onEnterFrame = function() {
    		this._y -= this.yMove;
    		this._x = Math.sin(this.a) * this.xMove + 150;
    		this.a += 0.2;
    		if (this._xscale > 0) {
    			this._xscale -= scaleFactor;
    			this._yscale -= scaleFactor;
    		}
    		if (this._y < 0) {
    			this.removeMovieClip();
    			delete this.onEnterFrame;
    		}
    	};
    }
    my_btn.onPress = function() {
    	stopped = !stopped;
    	if (!stopped){
    		createBubble();
    		trace("bubbles on")
    	}else{
    		trace("bubbles off")
    	}
    };
    Last edited by dawsonk; 08-22-2007 at 10:51 AM.

  7. #7
    Member
    Join Date
    Jun 2004
    Posts
    83
    Thank you dawsonk, thats what I want...nice solution as well!

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