code on 2008-12-18
package
{
import caurina.transitions.Tweener;
import flash.events.MouseEvent;
import flash.utils.Timer;
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.TimerEvent;
public class main extends MovieClip
{
public var container:MovieClip;
protected var funcSpeed:uint = 50;
protected var timerSpeed:uint = 1;
protected var count:uint = 1;
protected var drewNum:uint = 50;
public function main()
{
init();
}
protected function init()
{
setUI();
}
public function setUI()
{
container = new MovieClip;
addChild(container);
var timer:Timer = new Timer(timerSpeed,0);
timer.addEventListener(TimerEvent.TIMER, drewTimer);
timer.start();
}
protected function drewTimer(e:TimerEvent):void
{
var rnd = Math.ceil(Math.random() * funcSpeed);
if (rnd == 1)
{
trace(count);
var rectMC:drewRect = new drewRect();
container.addChild(rectMC);
count++
}
if (count > drewNum)
{
e.target.reset();
}
}
}
}
import caurina.transitions.Tweener;
import flash.utils.Timer;
import flash.display.MovieClip;
import flash.display.Shape;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.Rectangle;
class drewRect extends MovieClip
{
protected var rectMCContainer:MovieClip;
public var stageWidth:uint = 484;
public var stageHeight:uint = 490;
public var objMaxSize:uint = 100;
public var objMinSize:uint = 10;
protected var dragFlg = false;
public function drewRect()
{
rectMCContainer = drewRectMC(ramObjPosXUint(), ramObjPosYUint(), ramObjSizeUint(), ramObjSizeUint(), ramObjColorNum(), ramObjAngUint());
Tweener.addTween(rectMCContainer, { alpha:1, scaleX:1, scaleY:1, onComplete:mouseEventSet, time:2 } );
Tweener.addTween(rectMCContainer, { alpha:0, scaleX:0, scaleY:0, onStart:mouseEventStop, delay:15, time:2 } );
addChild(rectMCContainer);
}
protected function drewRectMC(XX:uint, YY:uint, wid:uint, hgt:uint, col:Number, ang:uint):MovieClip
{
var rectShape:Shape = new Shape;
rectShape.graphics.beginFill(col);
rectShape.graphics.drawRect(0, 0, wid, hgt);
rectShape.graphics.endFill();
var rectMC:MovieClip = new MovieClip;
rectMC.addChild(rectShape);
rectShape.x = -wid / 2;
rectShape.y = -hgt / 2;
trace(rectShape.x)
rectMC.rotation = ang;
rectMC.x = XX;
rectMC.y = YY;
rectMC.alpha = 0;
rectMC.scaleX = 0;
rectMC.scaleY = 0;
return rectMC;
}
protected function ramObjSizeUint():uint
{
var objSizeUint:uint;
objSizeUint = Math.ceil(Math.random() * (this.objMaxSize - this.objMinSize)) + this.objMinSize;
return(objSizeUint);
}
protected function ramObjPosXUint():uint
{
var ObjPosXUint:uint;
ObjPosXUint = Math.ceil(Math.random() * (this.stageWidth - this.objMaxSize*2)+this.objMaxSize);
return(ObjPosXUint);
}
protected function ramObjPosYUint():uint
{
var ObjPosYUint:uint;
ObjPosYUint = Math.ceil(Math.random() * (this.stageHeight - this.objMaxSize*2)+this.objMaxSize);
return(ObjPosYUint);
}
protected function ramObjAngUint():uint
{
var ObjAngUint:uint;
ObjAngUint = Math.ceil(Math.random() * 360);
return(ObjAngUint);
}
protected function ramObjColorNum():Number
{
return Math.ceil(Math.random() * 16777215);
}
protected function mouseEventSet():void
{
buttonMode = true;
addEventListener(MouseEvent.MOUSE_OVER, onMouseOverHandler);
addEventListener(MouseEvent.MOUSE_OUT, onMouseOutHandler);
addEventListener(MouseEvent.MOUSE_DOWN, onMouseDownHandler);
addEventListener(MouseEvent.MOUSE_UP, onMouseUpHandler);
stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUpHandler);
}
protected function onMouseOverHandler(e:MouseEvent):void
{
Tweener.addTween(e.target, { scaleX:1.2, scaleY:1.2, time:0.5 } );
}
protected function onMouseOutHandler(e:MouseEvent):void
{
Tweener.addTween(e.target, { scaleX:1, scaleY:1, time:0.5 } );
}
protected function onMouseDownHandler(e:MouseEvent):void
{
rectMCContainer.startDrag(false, new Rectangle(e.target.width/2, e.target.height/2, stageWidth - e.target.width, stageHeight-e.target.height));
dragFlg = true;
}
protected function onMouseUpHandler(e:MouseEvent):void
{
rectMCContainer.stopDrag();
dragFlg = false;
}
protected function mouseEventStop():void
{
if (dragFlg)
{
stopDrag();
}
buttonMode = false;
removeEventListener(MouseEvent.MOUSE_OVER, onMouseOverHandler);
removeEventListener(MouseEvent.MOUSE_OUT, onMouseOutHandler);
removeEventListener(MouseEvent.MOUSE_DOWN, onMouseDownHandler);
removeEventListener(MouseEvent.MOUSE_UP, onMouseUpHandler);
stage.removeEventListener(MouseEvent.MOUSE_UP, onMouseUpHandler);
}
}