More Fun With Flash

The Flash plugin is required to view this object.

Here’s a little thing that I wrote a while ago while learning the Flash particle system.  It just makes little light blurbs generate from your mouse pointer.  It’s pretty neat, and if you don’t know how to generate particle effects in Action Script 3, the code might help you out.  Check it out if you want to.

If you find it helpful or fun, let me know in the comments.  Thanks for reading!  Code when you click through…



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
var speed:Number = 15;
var totalBubbles:Number = 75;
var centerX:Number = stage.stageWidth / 2;
var centerY:Number = stage.stageHeight / 2;
var allBubbles:MovieClip = new MovieClip();
var singleBubble:bubble_mc;
 
addChild(allBubbles);
 
function moveage(e:Event):void {
	var bubble:bubble_mc;
	if (allBubbles.numChildren < totalBubbles) {
		addBubble();
	}
	for (var i:uint=0;i<allBubbles.numChildren;i++) {
		bubble = bubble_mc(allBubbles.getChildAt(i));
		bubble.y = bubble.y + Math.cos(bubble.angle);
		bubble.x = bubble.x + Math.sin(bubble.angle);
		bubble.alpha = bubble.alpha - bubble.alphaSpeed;
		if (bubble.alpha < 0) {
			//set new bubbles at mouse cursor
			bubble.y = mouseY;
			bubble.x = mouseX;
			bubble.alpha = 1;
		}
	}
}
 
function addBubble() {
	singleBubble = new bubble_mc();
	singleBubble.y = mouseY;
	singleBubble.x = mouseX;
	singleBubble.angle = Math.floor(Math.random() * 360);
	singleBubble.scaleX = singleBubble.scaleY = Math.random();
	if (singleBubble.scaleX < 0.3){
		singleBubble.scaleX = singleBubble.scaleY = 0.3;
	}
	singleBubble.alphaSpeed = Math.random() * 0.01;
	singleBubble.speed = Math.floor(Math.random() * speed) + 5;
	allBubbles.addChild(singleBubble);
}
 
 
addEventListener(Event.ENTER_FRAME, moveage);

Tags: , ,

Leave a Reply