views:

246

answers:

2

Does anyone know if its possible to access children elements in a SWC? I have created some MC's and inside of some of these MC's I have some dynamic textFields. I export the content to a SWC and load it into my Flex project. No problem loading it or accessing the parent elements, they display fine. But I want to access the textfields nestes in the MC's and modify the text. When I debug the app, I can see the textfields as child elements. It's typed as a TextField and the Instance Name is the same as input in the Flash IDE but I cannot access it. When Flex compiles it throws an error saying it doesn't recognize the method. I've tried to insert actionscript on the timeline, linked external classes and nothing can be accessed. Does anyone know of a way to do this?

A: 

It's hard to say since you're not showing your code that fails, but I suspect you're doing:

import myswc.*;

myswc.Symbol1.myTextField.text = "Foo"

instead of

var clip:MovieClip = new myswc.Symbol1();
clip.myTextField.text = "Foo"
Cory Petosky
I've placed my swc in the my Flex Build Path under a Library path. Therefor, the components that I am trying to access are instantly available by means of var comp:Sprite = new componentFromSWC();then I can access that element by referencing the comp variable. There is no import required because its in the build path. When I tried your method of referencing the symbol/element via the swc it fails to recognize it - throws a compiler error. Is there another wa I should be setting my swc import up? This just seemed to work first off and I assumed it could access all elements.
Daniel Dunn
The import is only necessary if you exported your symbols in a package besides the default one. It is good practice to package your classes properly. "myswc" is not a magical name here, it was a placeholder for whatever package you used in your symbol exports.More to the point, Sprite is not a dynamic class -- so instead of `comp.myTextField.text` try `comp["myTextField"].text`.
Cory Petosky
A: 

THANK YOU!!! That got it working.

comp['myTextField'].text = 'string';

Im glad you could understand my convoluted question.

Daniel Dunn
you should respond as a comment on his answer, and if it worked you should accept his answer.
Ryan Guill