1) You can generally trust the garbage collector to handle everything properly. It's typically event listeners that you need to be a little extra careful about. You don't necessarily need to remove every even listener. Some people go overboard with that. However, there are some things you should watch out for.
If your item renderer listens only to events dispatched by itself or its children, you should be fine. The item renderer will only hold a reference to itself, which the garbage collector won't have a problem with.
However, if your item renderer listens to events dispatched by something external (such as the stage), that's when it's important to remove the listener, or your item renderer may never get garbage collected because that external dispatcher will hold a reference to the item renderer.
In the case of adding listeners to the stage, it's good to rely on Event.ADDED_TO_STAGE
and Event.REMOVED_FROM_STAGE
. In the code below, a listener will always be safely removed from the stage.
public function new() {
super();
addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
addEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStage);
}
private function onAddedToStage(event:Event):Void {
stage.addEventListener(Event.RESIZE, stage_onResize);
}
private function onRemovedFromStage(event:Event):Void {
stage.removeEventListener(Event.RESIZE, stage_onResize);
}
(There's probably not many reasons why an item renderer would need to know when the stage resizes. It's just an example.)
2) You have a few options for custom vector skins.
- I think that SVG format can be used with the svg library.
- You can export a SWF file from Adobe Animate and use the swf library.
- Create a custom programmatic skin.
Exporting to PNG or another bitmap format is also possible.