アイコンドット化
自分のアイコンをドット化して遊んでみるテスト
//自分のアイコンをドット化して遊んでみるテスト
package{
import flash.display.*;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.net.URLRequest;
import flash.system.*;
import caurina.transitions.Tweener;
public class myIcon extends Sprite{
private const myIconURL:String = "http://ton1517.web.fc2.com/tonicon.jpeg";
private var loader:Loader = new Loader();
private var iconData:BitmapData;
public function myIcon(){
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
loader.load(new URLRequest(myIconURL), new LoaderContext(true));
}
private function onCompleteHandler(e:Event):void {
iconData = new BitmapData(loader.width, loader.height);
iconData.draw(loader);
for(var i:int = 0; i < iconData.height; i++){
for(var j:int = 0; j < iconData.width; j++){
var color:uint = iconData.getPixel(j, i);
if(color != 0xffffff){
var dot:Dot = new Dot(3, color);
dot.selfx = j * 4;
dot.selfy = i * 4;
dot.x = Math.random() * 400;
dot.y = Math.random() * 400;
dot.alpha = 0;
addChild(dot);
Tweener.addTween(dot,
{
x: j * 4,
y: i * 4,
alpha: 1,
delay: 4 * Math.random(),
time: 3
}
);
}
}
}
}
}
}
import flash.display.Sprite;
import flash.events.MouseEvent;
import caurina.transitions.Tweener;
class Dot extends Sprite{
public var size:int;
public var color:uint;
public var selfx:int;
public var selfy:int;
private var self:Dot;
function Dot(size:int, color:uint):void {
this.size = size;
this.color = color;
this.graphics.beginFill(color);
this.graphics.drawRoundRect(0, 0, size, size, 2, 2);
this.graphics.endFill();
self = this;
this.addEventListener(MouseEvent.MOUSE_OVER, onMouseOverHandler);
}
private function onMouseOverHandler(e:MouseEvent):void{
self.parent.addChild(self);
Tweener.addTween(self, {
x: selfx + Math.random() * 100 - 50,
y: selfy + Math.random() * 100- 50,
time: 1,
onComplete: function():void{
Tweener.addTween(self, {
x: selfx, y: selfy, time: 1,
transition: 'easeOutSine'
});
}
});
}
}