Welcome, Guest
  • Author Topic: CellRenderer problem  (Read 3415 times)

    gr0undtek

    • Server what's that
    • *
    • Posts: 7
      • View Profile
      • Email
    CellRenderer problem
    « on: 09/01/06, 19:02 »
    Hi,

    I have a cellRenderer that displays a button. I need the button since I need the functionality of the button component. Once I click the button though I want the button to disappear and some text to appear in its position. I know that I can have a movie clip with different icons, thus to show different ones for each state. But is it possible to have different components as well?

    Thanks in advance
    stelios

    Jorge Solis

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 14616
      • View Profile
    Re: CellRenderer problem
    « Reply #1 on: 09/02/06, 07:50 »
    Two components to show a text? Use the movieclips

    Jorge

    gr0undtek

    • Server what's that
    • *
    • Posts: 7
      • View Profile
      • Email
    Re: CellRenderer problem
    « Reply #2 on: 09/02/06, 09:57 »
    I probably didn't explain myself well, or didn't understand you.  :-\

    I have initially a button in the cell renderer. When I click the button I want the cellRenderer on the specific cell to display a text, instead of a button.
    So I can use a movieClip and different frames as the cellRenderer example with the cars.
    But in that example the different frames all contain icons. I need intially a button, then text. My question is can I use a button in frame one, and a TextArea in frame 5 for instance.
    If not any ideas on how can I resolve this?

    Thanks again
    stelios

    Jorge Solis

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 14616
      • View Profile
    Re: CellRenderer problem
    « Reply #3 on: 09/02/06, 12:55 »
    Sure you can

    Jorge

    gr0undtek

    • Server what's that
    • *
    • Posts: 7
      • View Profile
      • Email
    Re: CellRenderer problem
    « Reply #4 on: 09/02/06, 18:43 »
    Yep it seems to work fine :)
    thanks ;)

    gr0undtek

    • Server what's that
    • *
    • Posts: 7
      • View Profile
      • Email
    Re: CellRenderer problem
    « Reply #5 on: 09/06/06, 08:45 »
    too fast to talk...
    I have the following problem.
    I placed an eventListener into the movieClip that is the cellRenderer. Same as IconCellRenderer in your example. The listener works fine but it doesn't know in which cellIndex it is. So when it triggers and *should* change the playhead of the movieClip to the correct position, it cannot do it since it can't get the Item of the grid.
    Any ideas?

    Thanks
    Stelios

    Jorge Solis

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 14616
      • View Profile
    Re: CellRenderer problem
    « Reply #6 on: 09/06/06, 08:51 »
    Post related code

    Jorge

    gr0undtek

    • Server what's that
    • *
    • Posts: 7
      • View Profile
      • Email
    Re: CellRenderer problem
    « Reply #7 on: 09/06/06, 09:20 »
    There is a lot of code, so I just cut it down to the one in question. There might be some small errors here.
    //////////////////////////////////
    CellRenderer Code:
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    import mx.controls.DataGrid;
    import mx.core.UIComponent
    import test.as

    class ctRenderer extends UIComponent {

       var cell : MovieClip;
       var listOwner : MovieClip; // the reference we receive to the list
       var getCellIndex : Function; // the function we receive from the list
       var   getDataLabel : Function; // the function we receive from the list
       
       function ctRenderer()
       {
       }

       function createChildren(Void) : Void
       {   //cellIcon is the linkage name or our icon in the library
          cell = createObject("celltest", "Cell", 1, {styleName:this, owner:this});      
          size();
       }

       // note that setSize is implemented by UIComponent and calls size(), after setting
       // __width and __height
       function size(Void) : Void
       {
          cell.setSize(20, 20);
          cell._x = (__width)/2;
          cell._y = (__height)/2;
       }

       function setValue(str:String, item:Object, sel:Boolean) : Void
       {      
          //trace(getDataLabel());
          trace(item[getDataLabel()]);
          trace("kakaka");
          //trace(str);
          // to check id the cell is selected
          //var reallySelected:Boolean = selected != "normal" && listOwner.selectedNode == item;
          
          cell._visible = (item!=undefined);
          
               var temp:String = str;
          if(temp == "test") {
             trace("inloop");
             if(item!=undefined){
                trace("item defined: "+item[getCellIndex()]);
             }
             cell.gotoAndStop(10);
          }
          else if(temp != "test") {
             trace("gotU!");
             cell.gotoAndStop(2);
          }
       }

       function getPreferredHeight(Void) : Number
       {
          return 16;
       }

       function getPreferredWidth(Void) : Number
       {

    //////////////////////////////////////////////////////////////
    Code of test.as imported on frame 1:
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    import WatchButton.as
    import mx.controls.gridclasses.DataGridColumn;

    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // Set Data Grid Columns, Headers, CellRenderers
    testdatagrid1.removeAllColumns();

    var test_dgc:DataGridColumn = new DataGridColumn("test");
    testgrid1.addColumn(test_dgc);
    test_dgc.headerText = "test";
    test_dgc.cellRenderer = "ctRenderer";

    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // Add Data to datagrid
    var testUsers = new Array();
    testUsers.addItem({test:"join"});
    testUsers.addItem({test:"join"});
    testUsers.addItem({test:"join"});
    testgrid1.dataProvider = testUsers;

    // For join button CellRenderer
    testgrid1.getColumnAt(0).width = 60;
    testgrid1.getColumnAt(0).resizable = false;
    testgrid1.getColumnAt(0).cellRenderer = "ctRenderer";

    ////////////////////////////////////////////////////////////////////
    The code that resides in Frame 2, inside the cellTest MovieClip:
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    import ctRenderer.as

    var temp:ctRenderer = new ctRenderer();

    var testjoinBtnListener:Object = new Object();
    testjoinBtnListener.click = function(evt:Object) {
       trace("works till testListener");
       var test:String = "test";
       temp.setValue(test, evt, true);
    };

    Note that I get in the CellRenderer code this line: trace("item defined: "+item[getCellIndex()]); gives me undefined.

    Jorge Solis

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 14616
      • View Profile
    Re: CellRenderer problem
    « Reply #8 on: 09/06/06, 13:05 »
    createObject("celltest" ...

    What kind of object is this?
    If it's a simple MovieClip, use attachMovie instead.
    Do you get something as str/temp, If you did, then gotoAndStop it's fine, not sure why you need the cellIndex

    Jorge

    gr0undtek

    • Server what's that
    • *
    • Posts: 7
      • View Profile
      • Email
    Re: CellRenderer problem
    « Reply #9 on: 09/06/06, 13:19 »
    basically I did everything in a different way finally. And it works
    Sorry for the hassle
    STelios