PDA

View Full Version : Custom component


DiscoJimmy
12-20-2004, 06:27 PM
Ok, this may be a component question, or maybe just an AS question, I'm bad at both. I created a MC and then I rightclick it in the library and click 'Component Definition' - this allows me to add parameters and map them to internal variables, like txtA.text where txtA is a dynamic text field in the MC.
This works ok, and I can set the parameters at design time and when I run the movie the values map in correctly. What i can't seem to do is access/change those parameters at runtime. It works with the built-in components, for instance I can get btnGo.label at runtime, but I can't seem to read/write my custom component's parameters, like cmpA.A.
Is there something I'm not doing here, or are these parameters private somehow?

Any insight would great, and I swear I'm gonna buy an AS book this week and stop asking all these dumb questions.

DiscoJimmy

prisma
12-21-2004, 06:05 PM
It works for me:
Create a symbol.
Create a textField inside called 'tf1'.
Make the symbol a component; Variable:tf1.text, type:String.
Create an instance of the symbol called myMC.
Place the following code on the frame containing the instance: myMC.tf1.text = "test"

DiscoJimmy
12-21-2004, 06:33 PM
well, yes that does work, but what I was meant was that I can't refer to the parameter name at runtime. You don't even to make an MC a component to refer to text fields contained in it.
What I need to do is a add a custom parameter like 'Super' that maps to that tf1.text. And as I said, you can do this in the designer and it works, I just can't seem to use that parameter in AS at runtime.

prisma
12-21-2004, 06:48 PM
As far as I know the "name" colum of the component definition has no meaning at runtime. It's just how the parameter is called in the properties panel of the component's instances.

To do what you desire you could register the component to a class and use a setter function.

function set caption(value:String):Void {
tf1.text = value;
}
function get caption():String {
return tf1.text;
}

With this, if you change the myMC.caption, it whould change the text of the textfield.