A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Remove Movieclip CS3 AS3

  1. #1
    Member
    Join Date
    Jul 2008
    Posts
    94

    Remove Movieclip CS3 AS3

    Hi guys,

    i have some rain (a movieclip of a drop of water) that falls to the bottom of the stage, when it hits the bottom, it starts at a random x position and falls again.

    When the rain hits a box or the 'floor' i want it to play a splash movieclip (a 10 frame movieclip)

    the problem is, this splash clip only plays half way through (or something like that, its so hard to tell). another attempt i had had the splash occuring in the same place and repeating sorry for being such a n00b.

    Code:
    package {
    	import flash.display.Sprite;
    	import flash.display.MovieClip;
    	import flash.events.Event;
    	import flash.events.MouseEvent;
    
    	public class dripdrop2 extends MovieClip {
    		var drip:MovieClip = new drop;
    		var Box:MovieClip = new box;
    		var Splash:MovieClip = new splash;
    		
    		var gravity:Number = 0.9;
    		private var drips:Array;
    		private var count:int = 30;
    
    		public function dripdrop2() {
    
    			init();
    		}
    		
    		private function init():void {
    			Box.x = (0 - Box.width);
    			Box.y = stage.stageHeight - Box.height;
    			addChild(Box);
    			backg.addEventListener(MouseEvent.MOUSE_DOWN, doDrag);
    			drips = new Array();
    			for (var i:int = 0; i<count; i++) {
    				var drip:drop = new drop;
    				drip.y = -20*i;
    				drip.x = Math.random()*stage.stageWidth;
    				drip.vy = Math.random() * 20;
    				drips.push(drip);
    				addChild(drip);
    			}
    			addEventListener(Event.ENTER_FRAME, fall);
    		}
    		private function fall(event:Event):void {
    			Box.x += 1;
    			if(Box.x>stage.stageWidth + Box.width){
    				Box.x = 0 - Box.width;
    			}
    			for (var i:Number = 0; i<drips.length; i++) {
    				var drip:drop = drop(drips[i]);
    				drip.y += drip.vy;
    				drip.vy += gravity;
    				if (drip.hitTestObject(Box)) {
    					Splash.x = drip.x;
    					Splash.y = stage.stageHeight - Box.height;
    					addChild(Splash);
    					drip.vy = Math.random() * 2 - 1;
    					drip.y = -20;
    					drip.x = Math.random()*stage.stageWidth;
    				}else if(drip.y > 400){
    					Splash.x = drip.x;
    					Splash.y = stage.stageHeight;
    					parent.addChild(Splash);
    					drip.vy = Math.random() * 2 - 1;
    					drip.y = -20;
    					drip.x = Math.random()*stage.stageWidth;
    				}
    			}
    		}
    		private function doDrag(event:MouseEvent):void {
    			stage.nativeWindow.startMove();
    		}
    	}
    }
    really sorry as well for my awful choice of naming the different parts... i.e. the line "var drip:drop = drop(drips[i]);" lol

    any help, really really appreciated

    dave

    http://teaindreamland.co.uk/test/ is an example
    Last edited by sheepysheep60; 02-10-2009 at 12:22 PM.

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    The splash appears to be playing all the way through. The problem is that you only have a single splash. Each time a new collision is detected, the splash is moved to the new location.

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