I have a MXML with a form, and inside it, two TextInputs. I hate having any piece of code inside the MXML file (I come from a JavaScript formation) so I use a
mx:Script source='external.as'
tag to include any code used in any MXML file. The problem is that if I have this code on the external.as file:
private function populateFromForm():void{ var vo:ValidObject= new ValidObject(); vo.market = marketInput.text; vo.segment = segmentInput.text; vo.priceLow = priceLowInput.text; vo.priceHigh = priceHighInput.text; }
Where marketInput, segmentInput, priceLowInput and priceHighInput are TextInputs defined in the MXML file. When I try to complile I get a 1120: Access to undefined property XXXXX
I have tried adding this lines prior to the function:
public var marketInput:TextInput; public var segmentInput:TextInput; public var priceLowInput:TextInput; public var priceHighInput:TextInput;
But instead I get a 1151:A conflict exists with definition XXXX in namespace internal which makes perfect sense.
Is there a way to do this without having to pass all the input references to the function as parameters of it?
Doing a ‘code-behind’ is painful in Flex. There is no concept of partial classes or the flexibility of prototypal inheritance as in Javascript. Google for ‘code-behind in flex’ for many resources.
I think it’s better you get used to the idea of embedding code in mxml. Use script tags avoiding inline code as much as possible. If you have to write a lot of code within MXML, perhaps you may want to re-factor the code into multiple custom components. Bonus points if they are reusable.