Constructor to assign instance name from super constant when adding instance in Flash IDE?
I have a library object (SomethingMC
) which extends a custom class (Something
). Something
, in turn, extends MovieClip
.
If adding SomethingMC
to the stage within Flash CS3 IDE, is it possible for it's super class (Something
) to assign an instance name from a class constant (Something.THE_CONSTANT
)?
package
{
import flash.display.MovieClip;
import flash.events.Event;
public class Something extends MovieClip
{
public static const THE_CONSTANT:String = 'anInsanceName';
public function Something():void
{
addEventListener(Event.ADDED_TO_STAGE, assignInstanceName);
}
protected function assign开发者_运维问答InstanceName(event:Event):void
{
this.name = THE_CONSTANT;
}
}
}
The above does not work. It throws Error #2078: The name property of a Timeline-placed object cannot be modified.
if the instance is assigned a name in the IDE, and it just doesn't work if no name is assigned in the IDE.
I'm afraid the answer is no...
I don't think this is possible, but I like the idea. It would certainly be nice to be able to do this rather than having to name each key-framed instance of a DisplayObject you wish to target via it's instance name.
精彩评论