开发者

ActionScript 3 - referencing whith Static Methods

Is there a way to make an static method act over an object of its class that is already on the stage, without using the keyword "this"? I mean, like "generic o开发者_JAVA技巧bject of this class: do what I'm telling you to do, wathever your instance name"

My goal is to create an method that get called by any object of this class, based on the changing on the value of an external variable, but since I cannot use the "this" keyword to reffer to each instance, I could not figure out a solution.

Thanks in advance!


Not unless you have access that object some other way (something like 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 );
        }
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜