有没有办法使静态方法在不使用关键字"this"的情况下对其类的对象进行操作?我的意思是,就像"这个类的通用对象:做我告诉你要做的事情,改变你的实例名称"
我的目标是创建一个由此类的任何对象调用的方法,基于对外部变量值的更改,但由于我无法使用"this"关键字来引用每个实例,因此我无法找到解决方案。
提前感谢!
除非你可以通过其他方式访问该对象(如下所示):
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 );
}
}
}