0 Replies Latest reply on Dec 14, 2006 4:47 AM by ahugebug

    Strange Problem with removeChild()

    ahugebug
      Could someone help with this problem?

      Currently, I am developing a data driven application where the RIA is reactive to the data model sitting at the back with mySQL and PHP. At the start, it needs to dynamically generate a grid with 3 columns and a maximum of 6 rows. In the third column of each row exists a remove button which can take the row out of the grid visually and send a message to remove it in the database as well. The problem came when I tried to apply a composite(fade and wipeup) effect on the component. It removed fine, in the sense that when the remove handler method is called, it did what it should do. But about a second after the remove, this error was thrown:


      Main Thread (Suspended: TypeError: Error #1009: Cannot access a property or method of a null object reference.)
      mx.containers::GridRow/getStyle
      mx.containers.utilityClasses::BoxLayout/ http://www.adobe.com/2006/flex/mx/internal::widthPadding
      mx.containers.utilityClasses::BoxLayout/measure
      mx.containers::Box/mx.containers:Box::measure
      mx.core::UIComponent/mx.core:UIComponent::measureSizes
      mx.core::UIComponent/validateSize
      mx.core::Container/validateSize
      mx.managers::LayoutManager/mx.managers:LayoutManager::validateSize
      mx.managers::LayoutManager/mx.managers:LayoutManager::doPhasedInstantiation
      Function/ http://adobe.com/AS3/2006/builtin::apply [no source]
      mx.core::UIComponent/mx.core:UIComponent::callLaterDispatcher2
      mx.core::UIComponent/mx.core:UIComponent::callLaterDispatcher
      flash.utils::Timer/flash.utils:Timer::_timerDispatch [no source]
      flash.utils::Timer/flash.utils:Timer::tick [no source]

      The strange thing about this stack trace is that it doesn't point to anything in my code so I don't actually know what is providing the null reference. It also suggests the problem may lie not with my remove handling but the redrawing mechanism. Am I right to make these assumption?


      Here is how the I created the button in AS3.

      // associate the new remove button with the removeFactor() method
      new_remove.addEventListener(MouseEvent.CLICK, removeFactor);

      ..
      var appear:Parallel = BFFFilters.createParallel(BFFFilters.getWipe(BFFFilters.wipeDown,1500,gridRow),BFFFilters .getFade(BFFFilters.fadeIn,1500,gridRow));
      var disappear:Parallel = BFFFilters.createParallel(BFFFilters.getWipe(BFFFilters.wipeUp,1500,gridRow),BFFFilters.g etFade(BFFFilters.fadeOut,1500,gridRow));
      gridRow.setStyle("addedEffect",appear);
      gridRow.setStyle("removedEffect",disappear);
      grid.addChild(gridRow);


      And this is the remove method.

      var tButton:Button = Button(event.currentTarget);
      // tButton.parent.parent brings the object level from
      // Button -> GridItem -> GridRow
      var index:int = grid.getChildIndex(tButton.parent.parent);
      var norm_id:int = int((UIComponent(tButton.parent.parent)).id);
      trace("Remove index: " + index);
      var row:GridRow = GridRow(grid.getChildAt(index));
      ..
      grid.removeChildAt(index); // remove a row

      Thanks for the attention.