5 Replies Latest reply on May 13, 2009 5:03 PM by Gregory Lafrance

    How do you create a gridrow / griditem in as3 dynamicly

    tfcenturion

      Hi i have made a grid block to diplay certain colours but it makes the code look nasty.

       

      this is a breif look at the code

       

      <mx:Grid id="mxGrdColour" height="100%" horizontalGap="2" verticalGap="2" styleName="mxGrdStyleColour" left="1" right="3" top="1" bottom="3" >
                                          <mx:GridRow width="100%" height="100%">
                                              <mx:GridItem id="grdColour_GI0" width="100%" height="100%" click="mxGrdColourClicked(0)" />
                                              <mx:GridItem id="grdColour_GI1" width="100%" height="100%" click="mxGrdColourClicked(1)" />
                                              <mx:GridItem id="grdColour_GI2" width="100%" height="100%" click="mxGrdColourClicked(2)" />
                                              <mx:GridItem id="grdColour_GI3" width="100%" height="100%" click="mxGrdColourClicked(3)" />
                                              <mx:GridItem id="grdColour_GI4" width="100%" height="100%" click="mxGrdColourClicked(4)" />
                                          </mx:GridRow>

      </Grid>

       

       

      if it possiable to create this structure dynamicly in as3 so i can have it randon lengths.

       

      any help would be great or examples

       

      Thanks

       

      Paul

        • 1. Re: How do you create a gridrow / griditem in as3 dynamicly
          Gregory Lafrance Level 6

          It woiuld look even nastier in AS. Here is just initializing the Grid n AS:

           

                  mxGrdColour.percentHeight = 100; 
                  mxGrdColour.setStyle("horizontalGap", 2);
                  mxGrdColour.setStyle("verticalGap" = 2);
                  mxGrdColour.styleName = "mxGrdStyleColour"
                  mxGrdColour.setStyle("left", 1);
                  mxGrdColour.setStyle("right" = 3);
                  mxGrdColour.setStyle("top", 1);
                  mxGrdColour.setStyle("bottom"3);
          

          Better off sticking with MXML, although you could put this in an MXML component to keep the main app less cluttered:

           

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Grid xmlns:mx="http://www.adobe.com/2006/mxml" height="100%" 
            horizontalGap="2" verticalGap="2" styleName="mxGrdStyleColour" 
            left="1" right="3" top="1" bottom="3" >
            <mx:GridRow width="100%" height="100%">
              <mx:GridItem id="grdColour_GI0" width="100%" height="100%" click="mxGrdColourClicked(0)" />
              <mx:GridItem id="grdColour_GI1" width="100%" height="100%" click="mxGrdColourClicked(1)" />
              <mx:GridItem id="grdColour_GI2" width="100%" height="100%" click="mxGrdColourClicked(2)" />
              <mx:GridItem id="grdColour_GI3" width="100%" height="100%" click="mxGrdColourClicked(3)" />
              <mx:GridItem id="grdColour_GI4" width="100%" height="100%" click="mxGrdColourClicked(4)" />
            </mx:GridRow>
          </Grid>
          
          • 2. Re: How do you create a gridrow / griditem in as3 dynamicly
            tfcenturion Level 1

            thank you  for that quick response.

             

            Yes i do agree it does seem worse in as3.

             

            A question then, if you have time...

             

            Im still learning this flex and im looking into componants now but these grid items tag the click to a function in my main.mxml file,  could you explain how i would get them to call the function if there ia seperate mxml file or do these componant mxml file act the same way an include would in as3 ??

             

            I do thank you for your time on this..

             

            Paul

            • 3. Re: How do you create a gridrow / griditem in as3 dynamicly
              Gregory Lafrance Level 6

              You do an import, then use the Application.application object:

               

              import mx.core.Application;
              
              application.mxGrdColourClicked(0)
              application.mxGrdColourClicked(1)
              application.mxGrdColourClicked(2)
              application.mxGrdColourClicked(3)
              application.mxGrdColourClicked(4)
              
              

               

              But if these calls are attached to the grid row click events, you may want to have them call a method local to the component, and then call the main app method.

               

              You can't pass 0, 1, 2, 3, 4 into the click handler function though, so you may have to use a dataProvider to populate your grid, and then you will access the dataProvider index of the clicked grid row and pass that.

               

              If that sounds overly complex, we need more info on exactly what you are doing, and then can help, but Application.application is for calling main app functions from components.

               

              Of course, in a well designed loosely coupled app you would communicate with the main app using custom events (see FB3 help sys), but if you are just starting out that may be overkill.

               

              If my posts answer your question of help, please mark as such. Thanks!

              • 4. Re: How do you create a gridrow / griditem in as3 dynamicly
                tfcenturion Level 1

                Greg, Wow thank you for the reply.

                 

                Cant lie that is a little over my head but i will have a better look into it in the morning.

                 

                I do think i get the jest of it and the more i play with this flex the more i prefer it over flash.

                 

                As to what i am trying to do, im using the grid componant to create a user defined colour panel, the user can then choose the colour they wish, at the mo i have it so it just call a function and passes a number relating to the index of the arraycollection and colours the image.

                 

                again thank you for your time on this and with hope ill have the componant sorted.

                 

                Paul

                • 5. Re: How do you create a gridrow / griditem in as3 dynamicly
                  Gregory Lafrance Level 6

                  Sounds like you're on the right track. Post if you need more help, and the more sample code the better.