I am instantiating custom MXML components using a technique
similar to the following:
var classRef:Class =
flash.utils.getDefinitionByName("Components."+module) as Class;
var d:DisplayObject = new classRef() as DisplayObject;
where mainCanvas is a Canvas component on my main stage and d
is a reference to the custom component attached to the mainCanvas.
My question is what is the best practice means to pass data
to d such that it will be available upon instantiation. I am
looking to employ the constructor object concept from attachMovie
and createObject of AS 2.
Look up ClassFactory - but what you are doing isn't very
Flex-ish. The better way is to do:
var d:Whatever = new Whatever();
d.property1 = value;
d.property2 = value;
This is the way we do it within the Flex framework and is
pretty easy to understand. You might also want to look up the
commitProperties function and override that in your custom
component in case you need to combine or use your property values
while your component is initializing.