DZone 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

Snippets has posted 5883 posts at DZone. View Full User Profile

Blowing Bubbles

03.02.2007
| 1815 views |
  • submit to reddit
        // description of your code here

stop();

//setup the query objects
loadResponseObj = new LoadVars();
sendResponseObj = new LoadVars();

//setup the movie dimensions
movie_height 	= 400;
movie_width 	= 800;
clip_height 	= bubbleDummy._height;
clip_width		= bubbleDummy._width;

//Send a query to return a questions responses
function getResponses(intQuestion){
	sendResponseObj.sendAndLoad("http://localhost/nesta_questions/responses.php",loadResponseObj,"POST");
}

//Generate a bubble
function generateBubble() { 
	//Trace the response from the ResponseObject
	trace(loadResponseObj["response"+intResponse]);
	//Duplicate the bubble dummy
	bubbleDummy.duplicateMovieClip ("bubble" + intDepth, intDepth);
	
	//And select it
	objBubble = get("bubble" + intDepth);
	//Randomly place it, with a scale and opacity
	objBubble._x 				= random(movie_width - clip_width - 20)+ (clip_width / 2) + 10;
	objBubble._y 				= random(movie_height - clip_height - 20)+ (clip_height / 2) + 10;
	objBubble._xscale 			= 70;
	objBubble._yscale 			= 70;
	objBubble._alpha 			= 0;
	
	//Substitute in the response as dynamic text
	objBubble.txtResponse.text 	= loadResponseObj["response"+intResponse];
	
	objBubble.onEnterFrame = function() {
		if (this._xscale < 99) { // the bubble is under 99% of its size
			this._xscale += (100-this._xscale)/5;
			this._yscale += (100-this._yscale)/5;
			this._alpha += (100-this._alpha)/5;
		}
	}
	
	//Keep our records tidy
	intResponse ++;
	intDepth ++;
	
	if (intResponse > intResponseCount){ // we've reached the end of our responses
		intResponse = 0; 
	}
} 

//On getting a response from the query...
loadResponseObj.onLoad = function(success){
	if ((success)){ // we've loaded the response object
		trace("Loaded the response object");
		intResponseCount = this.n - 1;
		trace("There are " + this.n + " responses in total");
		intDepth = 0;
		intResponse = 0;
		//start blowing bubbles every 2 seconds
		generateBubbleId = setInterval(generateBubble, 2000, intResponse); 
	}else{
		trace("Ouch, a server error occured");
	}
} 

//Get response for question 2
getResponses(2);