I have a 2K mxml file that I want to break into smaller pieces. I thought making each of the different states/forms a component would do the job. First I took all the scripts and broke them the same so that I could include the script with the component. Was that the wrong approach to take?
When I tried to compile it, the scripts that referred to stuff in the main mxml and stuff in the component would get errors. In the main mxml I have the XML record received from an SQL database. In the component I have fields that are populated from that record and eventually may populate that record.
1) keep the scripting in the main mxml (how to reference it from the mxml)
2) keep the scripting in the component (how to reference data in main mxml)
Thanks In Advance
MXML files compile to classes and one MXML file doesn't have knowledge of the contents of the others just as a class only has knowledge of it'self or its super class.
It's generally bad practice to build components that are dependent on knowing what is inside the other components.
There are a few techniques at your disposal:
Parameters (passing refernces to the parent class data)
Public variables (not really recommended)
I suspect that your programming skills may not be up to using all those techniques yet.
I suspect you are right. And your wording was very kind. Here is what I've done so far:
- keep the scripts that reference both component properties and main data structures in the main mxml and prefex the component properties with the id of the component
- have the buttons (save, add, reset) dispatch events that are known to the main mxml via the instantiation of the component which calls the functions (there may be a better way to do this)
- separate component only functions (accessibility for now) and instantiate it in the component
I'm syntactly correct (no little red doohickies) if logically deficient. When I try to add the data in the component to the record I get an HTTP error, but I was getting that before and will have to research it.
BTW, I found the method was not in "Adobe Flex 3 Bible" (978 pages no CD $44.99) in which the index had no references to working with components. I did find it in "The Essential Guide to Flex 3" (579 pages w/CD $54.99) which did have a nice reference. Those are retail prices - web prices was a lot less for "Essential" and I got the other one for Christmas retail.