2 Replies Latest reply on Dec 6, 2010 5:05 AM by srini_7206

    How to remove spritevisualelement from group

    srini_7206

      Hi,

      I have drawn triangles using spritevisualelement and added that to Group.But when I try to remove the previously plotted elements using array ,those are not atually removed from the group instead the triangles are still visible.How to make them to be deleted from the Group.So that I can draw new triangles without overlapping.

       

      var tempArr:Array=[];

      function drawTriangles():void{

       

      for each(var item:SpriteVisualElement in tempArr){

       

           if(grpChart.contains(item)){

                     grpChart.removeElement(item);

           }

      }

      var sprite:SpriteVisualElement=new SpriteVisualElement();

       

      sprite.graphics.clear();

      sprite.graphics.lineStyle();

      sprite.graphics.beginFill();

      sprite.graphics.moveTo();

      sprite.graphics.lineTo();

      sprite.graphics.lineTo();

      sprite.graphics.moveTo();

      sprite.graphics.endFill();

       

      grpChart.addElement(sprite);//grpChart is Group

      tempAr.push(sprite);

       

      }

      Thanks

      Srini

        • 1. Re: How to remove spritevisualelement from group
          Shongrunden Adobe Employee

          Can you provide a small sample application that demonstrates this?  For example this seems to work fine for me:

           

          <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                         xmlns:s="library://ns.adobe.com/flex/spark">

              <fx:Script>
                  <![CDATA[
                      import spark.core.SpriteVisualElement;

                      private var mySVE:SpriteVisualElement;
                     
                      protected function addSVE():void {
                          mySVE = new SpriteVisualElement();
                          mySVE.graphics.clear();
                          mySVE.graphics.beginFill(0x0000FF);
                          mySVE.graphics.drawRect(0,0,100,100);
                          mySVE.graphics.endFill();
                          myGroup.addElement(mySVE);
                      }
                     
                      protected function removeSVE():void {
                          myGroup.removeElement(mySVE);
                      }
                  ]]>
              </fx:Script>

              <s:controlBarContent>
                  <s:Button label="add" click="addSVE()" />
                  <s:Button label="remove" click="removeSVE()" />
              </s:controlBarContent>
                     
              <s:Group id="myGroup" />
             
          </s:Application>
          • 2. Re: How to remove spritevisualelement from group
            srini_7206 Level 1

            Thank you Shongrunden,

            I am able to remove the spritevisualelement from group by using removeElementAt() method.

            But I am getting another issue as ,

            I am plotting the triangles on the group.When I drag slider then the  group is zoomed.In this view I am redrawing all the triangles.But some times at maximum zoomed level the triangles are not redrawn.What will be the issue.

            Thanks

            Srini

             

            Message was edited by: srini_7206

             

            Message was edited by: srini_7206