[FONT=Calibri]I’ve just started to learn Flex. One question I have is where you put the ActionScript code?[/FONT]
[FONT=Calibri]I know i can put it in several locations (e.g. inline, within a script-tag, in actionscript-files, in actionscript classes) but what’s the best way to go?[/FONT]
[FONT=Calibri]Up until now I haven’t done so much coding, so I have just written the code inside a <mx:Script>-tag in my MXML-file. I’m starting to realize though that having both MXML and ActionScript in the same file is a bit inconvinient when the amount of code increases.[/FONT]
[FONT=Calibri]Since I come from the dark side (Microsoft), I’m used to having to files for each page/component; one with the “UI code” (MXML in this case) and one with the logic (AS in this case). I like that model, so I tried to do something similiar in Flex. My MXML-file looks like this:[/FONT]
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" applicationComplete="MainCode()">
<mx:Script source="MainCode.as" />
<!-- Other MXML code -->
</mx:Application>
[FONT=Calibri]Then I create the MainCode.as and give it a function called MainCode(). That way, I now have the code in a separate file/class, and themethod becomes the starting point of the execution. Kind of like the “document class” in Flash.[/FONT]
[FONT=Calibri]First, this seemed like a good solution to me BUT soon I realized it has a big flaw. Since the class is not hard linked to the MXML, I will not get any intellisense/codehints about the components/controls I use in the MXML (at least I don’t in FlashDevelop).[/FONT]
[FONT=Calibri]So, how do you do it? Is there a way that is considered “best practice”?[/FONT]