Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Blowing Bubbles (See related posts)

// description of your code here

   1  
   2  stop();
   3  
   4  //setup the query objects
   5  loadResponseObj = new LoadVars();
   6  sendResponseObj = new LoadVars();
   7  
   8  //setup the movie dimensions
   9  movie_height 	= 400;
  10  movie_width 	= 800;
  11  clip_height 	= bubbleDummy._height;
  12  clip_width		= bubbleDummy._width;
  13  
  14  //Send a query to return a questions responses
  15  function getResponses(intQuestion){
  16  	sendResponseObj.sendAndLoad("http://localhost/nesta_questions/responses.php",loadResponseObj,"POST");
  17  }
  18  
  19  //Generate a bubble
  20  function generateBubble() { 
  21  	//Trace the response from the ResponseObject
  22  	trace(loadResponseObj["response"+intResponse]);
  23  	//Duplicate the bubble dummy
  24  	bubbleDummy.duplicateMovieClip ("bubble" + intDepth, intDepth);
  25  	
  26  	//And select it
  27  	objBubble = get("bubble" + intDepth);
  28  	//Randomly place it, with a scale and opacity
  29  	objBubble._x 				= random(movie_width - clip_width - 20)+ (clip_width / 2) + 10;
  30  	objBubble._y 				= random(movie_height - clip_height - 20)+ (clip_height / 2) + 10;
  31  	objBubble._xscale 			= 70;
  32  	objBubble._yscale 			= 70;
  33  	objBubble._alpha 			= 0;
  34  	
  35  	//Substitute in the response as dynamic text
  36  	objBubble.txtResponse.text 	= loadResponseObj["response"+intResponse];
  37  	
  38  	objBubble.onEnterFrame = function() {
  39  		if (this._xscale < 99) { // the bubble is under 99% of its size
  40  			this._xscale += (100-this._xscale)/5;
  41  			this._yscale += (100-this._yscale)/5;
  42  			this._alpha += (100-this._alpha)/5;
  43  		}
  44  	}
  45  	
  46  	//Keep our records tidy
  47  	intResponse ++;
  48  	intDepth ++;
  49  	
  50  	if (intResponse > intResponseCount){ // we've reached the end of our responses
  51  		intResponse = 0; 
  52  	}
  53  } 
  54  
  55  //On getting a response from the query...
  56  loadResponseObj.onLoad = function(success){
  57  	if ((success)){ // we've loaded the response object
  58  		trace("Loaded the response object");
  59  		intResponseCount = this.n - 1;
  60  		trace("There are " + this.n + " responses in total");
  61  		intDepth = 0;
  62  		intResponse = 0;
  63  		//start blowing bubbles every 2 seconds
  64  		generateBubbleId = setInterval(generateBubble, 2000, intResponse); 
  65  	}else{
  66  		trace("Ouch, a server error occured");
  67  	}
  68  } 
  69  
  70  //Get response for question 2
  71  getResponses(2);

You need to create an account or log in to post comments to this site.


Click here to browse all 5556 code snippets

Related Posts