有没有办法让静态方法对已经在舞台上的类的对象进行操作,而不使用关键字“this”?我的意思是,就像“这个类的通用对象:做我要告诉你的事情,看你的实例名称”
我的目标是根据外部变量值的变化创建一个被该类的任何对象调用的方法,但由于我不能使用“this”关键字来对每个实例进行调用,我可以没有找到解决方案。
提前致谢!
答案 0 :(得分:0)
除非您以其他方式访问该对象(如下所示):
package
{
import flash.display.MovieClip
import flash.events.Event
public class Something extends MovieClip
{
private static var group:Vector.<Something> = new Vector.<Something>();
public function Something()
{
// doing this on added and removed is generally more reliable.
// BUT! it does not give you accesses to all instances, only the
// ones which currently have a parent
addEventListener( Event.ADDED, addedHandler );
// that said, since AS3 has no destructor, removed is the only
// way to clean up instances
addEventListener( Event.REMOVED, removeHandler );
}
public static function doSomethingWithClass():void
{
for( var i:int = 0; i < group.length; i++ )
{
trace( group[ i ] );
}
}
private function addedHandler( event:Event ):void
{
group.push( this );
}
private function removeHandler( event:Event ):void
{
group.splice( group.indexOf( this ), 1 );
}
}
}