PDA

View Full Version : Where do I hook up my as3 file?


markww
11-17-2008, 09:07 PM
Hi,

I need a quick bit of help in getting going -

I just got FlexBuilder3 - where can i hook up an as3 file to it? I mean for example I have the following mxml file:


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
backgroundGradientColors="[0xFFFFFF,0xAAAAAA]"
horizontalAlign="left"
verticalGap="15" horizontalGap="15" >
<mx:HBox width="100%">
<mx:Label text="My pathetic project:"/>
<mx:TextInput/>
<mx:Button label="Wow"/>
</mx:HBox>

</mx:Application>


that's great and all, but I want some "main()" function in a separate as3 file where I can maintain state variables, and get going with using as3 to interact with the visual elements. I figured out how to do that for flash cs3 but not flex. All the different names are beginning to give me a headache.

Anyway any info would be great,

Thanks

drkstr
11-18-2008, 12:23 AM
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
creationComplete="onCreationComplete();">

<mx:Script>
<![CDATA[

//this is so much easier to read then keeping it in a seperate file
private function onCreationComplete(): void {
//start doing stuff
}
]]>
</mx:Script>

</mx:Application>

But you can also

<mx:Script source="script_file.as" />

I used to do it this way but opening two different files to look at code for the same class started to become annoying. I suggest keeping it in a Script block with your mxml, but that's just a personal preference.


Best Regards,
~Aaron