2007/6/23

會連鎖引爆的球(類別應用)

import mx.utils.Delegate;


class ball extends MovieClip
{
var _target:MovieClip;
public var id:Number;
public var start_hit=0;

private static var all_of_class:Array=new Array();

public function ball(parent:MovieClip,ball_name:String,icon_photo:String)
{
_target=parent.attachMovie(icon_photo,ball_name,
parent.getNextHighestDepth(),{_x:Math.random()*Stage.width,_y:Math.random()*Stage.height});
_target.stop();
_target.onEnterFrame=Delegate.create(this,freerun);
_target.onPress=Delegate.create(this,onpress_fun);

id=all_of_class.push(_target)-1; //矩陣長度減一
trace(id);
}

public function freerun(sss:String)
{
_target._x+=(Math.random()*Stage.width-_target._x)*0.05;
_target._y+=(Math.random()*Stage.height-_target._y)*0.05;

check_hit()
if(_target._currentframe==_target._totalframes)
{
_target.removeMovieClip();
}
}
public function onpress_fun()
{
start_hit=1;
trace(_target+"press");
}


public function check_hit()
{

if(start_hit==1)
{
_target.play()
for(var i=0;i
{
if(_target!=all_of_class[i] &&_target.hitTest(all_of_class[i]))
{
var tmp=all_of_class[i];
tmp.onPress();
}
}
}
}
}

沒有留言: