3 Replies Latest reply on Sep 20, 2011 2:52 PM by MatteoLegittimo

    Add custom class to display list

    MatteoLegittimo Level 1

      Hi,

      im new in flex.

       

      In a flex mobile project im tryin to add my custom class to my view:

       

      <?xml version="1.0" encoding="utf-8"?>
      <s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
              xmlns:s="library://ns.adobe.com/flex/spark" title="HomeView" creationComplete="complete(event)">
          <fx:Script>
              <![CDATA[
                  import GridView;
                  import Model;
                 
                  import mx.events.FlexEvent;
                 
                  private var grid:GridView
                  private var model:Model
                 
                  protected function complete(event:FlexEvent):void{
                     model = new Model()
                      grid = new GridView(model)
                      gr.contentGroup.addElement(grid)

                  }
                 
              ]]>
          </fx:Script>
          <fx:Declarations>
              <!-- Place non-visual elements (e.g., services, value objects) here -->
          </fx:Declarations>
          <s:BorderContainer id="gr">
             
          </s:BorderContainer>
         
      </s:View>

       

       

      but i get this error:

       

      1067: Implicit coercion of a value of type:GridView to an unrelated type mx.core:IVisualElement.

       

      is not possible to add a pure actionscript class?

      thanks a lot

        • 1. Re: Add custom class to display list
          Jason Szeto Level 3

          Your GridView class probably doesn't implement the IVisualElement interface. UIComponent implements this interface. I recommend you create a UIComponent, add that to the BorderContainer and then add your GridView to the UIComponent.

           

          Also, don't add the UIComponent to the BorderContainer's contentGroup. Just add it directly to the BorderContainer.

           

          var uic:UIComponent = new UIComponent();

          gr.addElement(uic);

          uic.addChild(grid);

           

          Jason

          • 2. Re: Add custom class to display list
            MatteoLegittimo Level 1

            Great, thanks a lot!!!

            So if i have a custom class i have always to put before in a UIComponent or implement the IVisualElement interface!?

            Why:

            gr.addElement(uic);

            and not

            gr.contentGrroup.addElement(uic);

            When use contentGrroup???

             

            thanks again!

            • 3. Re: Add custom class to display list
              MatteoLegittimo Level 1

              ...and my last question...

               

              why in my creation complete event

               

              protected function complete(event:FlexEvent):void{

                         

                              grid = new GridView

                              uiComponent = new UIComponent

                              gridContainer.addElement(uiComponent)

                              uiComponent.addChild(grid);

                              gridWidth=(width-grid.width)/2

                               //

                              stage.scaleMode = StageScaleMode.NO_SCALE

                              trace(stage)

                     

                          }          

               

              stage is null?