And the final reply to myself. I'm still extending UIComponent but that's about it, and I've added an [Inspectable] metadata structure, using a get/set function pair to update a parameter I declare.
Code:
package com.virtualight.examples{
import flash.display.Sprite;
import fl.core.UIComponent;
import flash.text.TextField;
public class myLabel extends UIComponent {
public var label_txt:TextField;
public var defaultLabel:String = "My Label";
public function myLabel() {
super();
labelname = defaultLabel;
}
override protected function configUI():void {
super.configUI();
label_txt = new TextField();
addChild(label_txt);
}
[Inspectable(defaultValue="My Label")]
public function get labelname():String {
return label_txt.text;
}
public function set labelname(value:String):void {
// Value is the same as what is already set.
if (value == labelname) {
return;
}
// Value in the PI is the default.
if (componentInspectorSetting && value == defaultLabel) {
return;
}
label_txt.text = value;
}
}
}
What I hadn't realized earlier is that the metadata/get/set function pair declares the parameter/variable. If you want to set the type of the parameter, you do that in the [Inspectable(defaultValue="Label", type="String")].
I realize this is probably old hat for everyone else, but I'm finding it instructive to try to create a component from scratch. Yes, I'm still extending UIComponent, but next I'll just try extending MovieClip and see if the metadata structure still works.
One thing that had me really confused is that the built-in Label component uses the word text as the parameter name, which is really confusing that you can use a reserved word as a parameter name. And the Jeff Kamerer tutorial similarly uses dataProvider as a parameter name. The Flash script editor clearly shows these two as reserved words.
Jennifer
PS Oh, and if you use the clean up formatting button in the script editor, it adds a semicolon at the end of the metadata, which really screws up things.
PPS Again, I don't know why I'm telling this to other people who may have already figured it out, but writing it down here helps cement the idea in my brain.