flash on 2009-7-15
BitmapとBitmapDataのテスト
使わないときはほんと使わないけど、使い慣れるとほんと便利なので
いろいろ実験
package{
import flash.display.*;
import flash.events.*;
/*
BitmapとBitmapDataのテスト
使わないときはほんと使わないけど、使い慣れるとほんと便利なので
いろいろ実験
*/
public class zonolibMoz0 extends MovieClip{
private var lineWidth:Number=40;
private var lineHeight:Number=40;
private var yPos:Number=0;
private var j:int = 0;
public function zonolibMoz0():void{
makeLine();
stage.addEventListener(MouseEvent.MOUSE_DOWN, _mouseDown);
}
private function makeLine():void{
//Bitmapの生成
for(var i:int=0; i<Math.floor(stage.stageWidth/lineWidth); i++){
var bmd:BitmapData = new BitmapData(lineWidth * 2, lineHeight * 2, false, Math.random() * 0xffffff);
var bmp:Bitmap = new Bitmap(bmd);
bmp.x = i*lineWidth;
bmp.y = j *lineHeight;
var thisMC:MovieClip = new MovieClip();
thisMC.addChild(bmp);
thisMC.addEventListener(MouseEvent.MOUSE_OVER, _mouseOver);
this.addChild(thisMC);
}
if(Math.floor(stage.stageHeight/5) > j){ j++; makeLine();}
}
private function clearLine(event:Event):void{
for(var i:int=0; i<this.numChildren; i++){
this.removeChild(this.getChildAt(i));
}
if(this.numChildren == 0){
this.removeEventListener(Event.ENTER_FRAME, clearLine);
j=0;
makeLine();
}
}
private function _mouseOver(event:Event):void{
trace(event.currentTarget.parent.getChildIndex(event.currentTarget));
event.currentTarget.parent.setChildIndex(event.currentTarget, 0);
if(event.currentTarget.alpha > 0){ event.currentTarget.alpha -= 0.1;}
trace(event.currentTarget.parent.getChildIndex(event.currentTarget));
}
private function _mouseDown(event:Event):void{
event.currentTarget.removeEventListener(MouseEvent.MOUSE_DOWN, _mouseDown);
event.currentTarget.addEventListener(MouseEvent.MOUSE_DOWN, _mouseDown);
if(this.numChildren >0){this.addEventListener(Event.ENTER_FRAME,clearLine);}
}
}
}