4 Replies Latest reply on May 11, 2010 9:12 AM by kkonrad

    Removing MediaElements at runtime

    kkonrad Level 1



      is it possible to remove a MediaElement from the MediaContainer at runtime? I display a few ImageElements in a SerialElement but the size of each image is different. So when the second image is smaller then the first it overlaps the first one but the edged of the first one are still visible. Thats why I would like to remove the first image completly from the display. Is this possible?


      I tried this by using the the mediaContainer.removeChild(DisplayObject) function but I get a


      Error: The direct addition or removal of display objects onto a MediaContainer is prohibited.


      So how is best practice to add or remove display objects?

        • 1. Re: Removing MediaElements at runtime
          Edwin van Rijkom Level 2

          The display objects of children in a SerialElement should never be on display concurrently. If you find that to be the case please file a bug:



          To remove the display object of a media element from a container you will have to remove the media element itself, either from the container if it's been added there directly, or from the composition that got added to the container.

          • 2. Re: Removing MediaElements at runtime
            kkonrad Level 1

            This doesn't work out for me.


            I add a listener to my MediaPlayer


            mediaPlayer.addEventListener(TimeEvent.COMPLETE, onTimeComplete);


            When the playtime of the composition is over the listener function is going to be called. This is where I remove my media elements from the composition:


            private function onTimeComplete(e:TimeEvent):void


            The media player stops but all medias are still visible on stage.


            What I'm doing wrong?

            • 3. Re: Removing MediaElements at runtime
              bringrags Level 4

              Try MediaContainer.removeMediaElement(serialElement).

              • 4. Re: Removing MediaElements at runtime
                kkonrad Level 1

                Doing this throughs a:


                Error: Invalid parameter passed to method
                     at org.osmf.containers::MediaContainer/removeMediaElement()[C:\Dev\osmf\public\trunk\framework\OSMF\org\osmf\containers\MediaContainer.as:164]...


                But I tried it directly with an media element of the composition and it worked out: