1 Reply Latest reply on Jun 7, 2009 8:38 PM by moshecristel

    removedEffect error - Yet another Flex bug?

    moshecristel

      Is it just me or are there a lot of inexcusible bugs in the Flex framework?  Maybe I'm just not used to working with a "fledgling" technology, I don't know.  But today I ran into an error with the removedEffect of HBox.  I've added a removed effect to the box and sometimes when I try to remove a bunch of items at roughly the same time, I get this error:

       

      RangeError: Error #2006: The supplied index is out of bounds.

      at flash.display::DisplayObjectContainer/addChildAt()

      at mx.core::UIComponent/http://www.adobe.com/2006/flex/mx/internal::$addChildAt()

      at mx.core::Container/addChildAt()

      at mx.effects::EffectManager$/removedEffectHandler()

      at Function/http://adobe.com/AS3/2006/builtin::apply()

      at mx.core::UIComponent/callLaterDispatcher2()

      at mx.core::UIComponent/callLaterDispatcher()

       

      I've Googled it and some folks seem to have had a similar problem but I haven't seen a workaround.  Any ideas?

       

      Thanks in advance,

      Moshe

        • 1. Re: removedEffect error - Yet another Flex bug?
          moshecristel Level 1

          Seems like I was able to work around it by bypassing the removedEvent trigger and just creating triggering my own effect.  I have quite a bit of code so the explanation won't really be done justice by cutting and pasting so I'll try and improvise:

           

          A little more background... I've been having quite a few issues with the TileList so I've decided to try and create a simple TileList of my own that has only the functionality I need.  The "item renderers" are just mini-HBoxes within a larger "TileList" HBox.  The renderers designate an effect:

           

          <mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml" >

           

                <mx:Parallel id="removedBlurEffect" target="{this}" duration="200"> 
                      <mx:Resize heightFrom="{this.height}" heightTo="0"/>
                      <mx:Blur blurYFrom="0" blurYTo="30" />
                      <mx:Fade alphaFrom="1" alphaTo=".75" />
                </mx:Parallel>

           

              ... OTHER STUFF ...

           

          </mx:HBox>

           

          Later the containing HBox responds to removals from the data provider ArrayCollection and rather than removing the corresponding child HBox, it fires the effect and only once the effect has ended does it remove the child...

           

          private function onCollectionChange(event:CollectionEvent):void

          {
              if(event.kind != CollectionEventKind.REMOVE) return;

            

              // Trigger the effect for each of the items that have been removed

              for(var j:int = 0; j < event.items.length; j++)

              {

                    // Cast the current data item to be removed (perhaps this is not necessary)

                    var eventUploadableImage:UploadableImage = UploadableImage(event.items[j]);

                    // Look through the children to find the item that has been removed

                    var children:Array = this.getChildren();

           

                    for(var i:int = 0; i < children.length; i++)

                    {

                        var currRenderer:ImageTileDisplayItemRenderer = ImageTileDisplayItemRenderer(children[i]);

                        var currImage:UploadableImage = currRenderer.uploadableImage;
                        if(currImage == eventUploadableImage)

                        {

                              currRenderer.removedBlurEffect.addEventListener(EffectEvent.EFFECT_END, onRemoveEffectComplete);         

                              currRenderer.removedBlurEffect.play();

                              break;

                        }

                    }

              }
          }

           

          private function onRemoveEffectComplete(event:EffectEvent):void
          {
               var renderer:ImageTileDisplayItemRenderer = ImageTileDisplayItemRenderer(Parallel(event.currentTarget).target);
               renderer.removeEventListener(EffectEvent.EFFECT_END, onRemoveEffectComplete);
              this.removeChild(renderer);
          }

           

          Anyway, seems to work so far.  I'm definitely open to a better way of doing this.

           

          Thanks!

          Moshe