# As3 Random circle with blendMode

**URL:** <https://forum.kirupa.com/t/as3-random-circle-with-blendmode/279678>\
**Category:** contests\
**Created:** [January 17, 2009, 1:55pm UTC](https://forum.kirupa.com/t/as3-random-circle-with-blendmode/279678 "2009-01-17T13:55:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![egoldy](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/egoldy/32/385_2.png) [@egoldy](https://forum.kirupa.com/u/egoldy)\
**Post date:** [January 17, 2009, 1:55pm UTC](https://forum.kirupa.com/t/as3-random-circle-with-blendmode/279678/1 "2009-01-17T13:55:12Z")

</div>

I changed my old As2 version to As3 version. here is the preview effect:

[http://webstudio.com.cn/test/FXpression09/](http://webstudio.com.cn/test/FXpression09/)

Mouse down to change the effect. 🙂

Main.as

```auto

package{	
	import flash.display.*;
	import flash.events.*;
	import flash.display.Stage;
	import flash.display.StageScaleMode;
	
	public class Main extends MovieClip {
		
		private var _base:Sprite;		
		private var mc:partical;
		private var pNum:Number =25;
		private var cX:Number =100;
		private var cY:Number =20;
		private var xSpread:Number =300;
		private var ySpread:Number =300;
		private var pScale:Number =1.6;
		private var pblend:String ="add";
				
		public function Main(){			
			_base = new Sprite();
			addChild(_base);
			
			init();			
			stage.scaleMode = StageScaleMode.NO_SCALE;					
			_base.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownListener);
		}
		private function init():void{
			for(var i:int=0;i<pNum;i++){
				mc = new partical();
				_base.addChild(mc);							
				mc.x = cX+Math.random()*xSpread;
				mc.y = cY+Math.random()*ySpread;
				mc.scaleX =mc.scaleY= pScale+Math.random()*0.5+2.5;
				
				mc.blendMode = pblend;
				mc.cacheAsBitmap = true;
				
				mc.tx = Math.random()*360; 
                                mc.ty = Math.random()*360; 
     
                                mc.xtemp = Math.random()/8; 
                                mc.ytemp = Math.random()/8; 
    
                                mc.xd = Math.random()*20+1; 
                                mc.yd = Math.random()*20+1; 
                                mc.x0 = mc.x; 
                                mc.y0 = mc.y; 
               				
				mc.gotoAndStop(Math.round(Math.random()*5)+1);				
				
				mc.addEventListener(Event.ENTER_FRAME, enterFrameListener);
               
				
			}			
		}
		private function enterFrameListener(e:Event):void{
			   var tempmc:MovieClip = e.target as MovieClip;
			   tempmc.tx +=tempmc.xtemp;
			   tempmc.ty +=tempmc.ytemp;
			   tempmc.x = tempmc.x0+Math.sin(tempmc.tx)*tempmc.xd;
			   tempmc.y = tempmc.y0+Math.cos(tempmc.ty)*tempmc.yd;
			
		}
		private function mouseDownListener(e:MouseEvent):void{
			//refresh code here
			clear();
			init();
		}
		
			// clear the former item
		private function clear():void {
			var i:Number, mc:DisplayObject;
			for (i=_base.numChildren-1;i>0;i--) {
				mc = _base.getChildAt(i);
				mc.removeEventListener(Event.ENTER_FRAME, enterFrameListener);
				_base.removeChild(mc);
			}
		}
	}
	
}

```
