PDA

View Full Version : Separate code?


ripvtech
12-05-2006, 05:52 PM
Hi all,

I am wondering what the best way to separate/clean up my code in order to make it easily readable. For example I have a viewstack and in total it has about 200 lines of code. Should I put it in it's own mxml component file?

I have tried putting it in it's own mxml component file and have had issues with errors being reported from flex that my actionscript cannot access the text fields and such in my component file.

Anyhow, I'm really looking for suggestions. Flex is still really new to me and I'm sure if an expert looked at my code it would make them sick :\

Thanks,
JD

ripvtech
12-06-2006, 01:54 PM
Ok, so let me ask this, how are your flex2 programs structured?

I'm really not comfortable with classes and such. I'm trying to get a handle of this.

My code just looks too sloppy to me. I've got one MXML file that has everything in my application in that MXML file. how can I get the different canvas' out of there. Such as viewstacks and whatnot.

feanish
12-06-2006, 04:26 PM
File->New->Component, "Canvas" for a new Canvas-based component.

Take the old code, put it in the component.

<mx:Canvas id="canvasA">
<mx:Button id="buttonA" />
</mx:Canvas>


becomes:

<ns1:CanvasAComponent id="canvasA" />


with CanvasAComponent =

<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Button id="buttonA" />
</mx:Canvas>


After that, your actionscript should work exactly the same way... If you're having problems, use the IDE to drop the new component on the screen, it'll add the proper namespace for you.

ripvtech
12-07-2006, 07:46 PM
Thank you for your reply!

ok here is my component


<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Button label="Search" click="changeit()" horizontalCenter="0" top="10"/>
<mx:Button id="btnBrowse" label="Browse Files" width="121" click="changeView(event, cnvsSearch)" horizontalCenter="0" top="42"/>
<mx:Button y="72" label="Create New File" width="121" horizontalCenter="0" click="changeView(event, cnvsNewFile)"/>
<mx:Button y="102" label="Archive Old Files" width="121" horizontalCenter="0" click="changeView(event, cnvsArchive)"/>
<mx:Button y="132" label="Administration" width="121" horizontalCenter="0" click="changeView(event, cnvsAdmin)"/>
</mx:Canvas>



and here is how I'm calling it in the main MXML file:


<custom:startCNVS id="cnvsStart" horizontalCenter="0" hideEffect="{fadeOut}"/>


I'm getting errors as follows:


1180: Call to a possibly undefined method changeit.
1120: Access of undefined property cnvsSearch.
1180: Call to a possibly undefined method changeView.
1180: Call to a possibly undefined method changeView.
1180: Call to a possibly undefined method changeView.
1180: Call to a possibly undefined method changeView.


What am I doing wrong? I do not get any errors when everything is sitting in the Main MXML file(I do have the actionscript in it's own file).