2 Replies Latest reply on Oct 16, 2008 11:38 AM by Newsgroup_User

    dynamic image click event

    nkollipara
      I have created 5 images dynamically and those images are assigned to array


      var image1:Image=new Image();
      for(i=0;i<5;i++){
      vbox=new VBox();
      image1=new Image();
      image1.source="../images/deleteimage1.jpg";
      arr11 =image1;
      image1.addEventListener(MouseEvent.MOUSE_MOVE,changecursor);
      image1.addEventListener(MouseEvent.CLICK,delrow);
      vbox.addChild(arr11
      );
      tile3.addChild(vbox);
      }


      how can we identify the position of the image


      private function delrow(event:MouseEvent):void{
      var img:Image=new Image();
      Alert.show("l="+arr11.length);
      for(var i:int=0;i<arr11.length;i++){
      img=arr11 ;
      //here we need to place a condition to identify the image
      img.removeChildAt(i);

      }
      }


      suggest any solution

      thanks in advance
        • 1. Re: dynamic image click event
          Gregory Lafrance Level 6
          There seems to be lots of problems with this code to begin with:

          arr11 = image1;
          Can't assign an image to an array like that.
          arr11 = [image1];
          -----------------------------------------------------------
          vbox.addChild(arr11);
          Can't add an array to the display list.
          -----------------------------------------------------------
          img = arr11;
          Can't assign an array to an image.
          img = arr11[0];
          -----------------------------------------------------------
          img.removeChildAt(i);
          Can't use Image as a container.
          • 2. Re: dynamic image click event
            Level 7

            "Greg Lafrance" <webforumsuser@macromedia.com> wrote in message
            news:gd7sht$4if$1@forums.macromedia.com...
            > There seems to be lots of problems with this code to begin with:
            >
            > arr11 = image1;
            > Can't assign an image to an array like that.
            > arr11 = [image1];

            Looked to me like he was adding images to an array:
            arr11 =image1;

            (note the i, which you stripped)

            > -----------------------------------------------------------
            > vbox.addChild(arr11);
            > Can't add an array to the display list.

            But you can add an image _in_ an array to the display list:
            vbox.addChild(arr11
            );

            (again, note the i)

            > -----------------------------------------------------------
            > img = arr11;
            > Can't assign an array to an image.
            > img = arr11[0];

            But you can assign an image _in_ an array to an image type variable.
            > -----------------------------------------------------------
            > img.removeChildAt(i);
            > Can't use Image as a container.

            Agreed.

            Here's some code that may work:

            private function delrow(event:MouseEvent):void{
            var img:Image=event.currentTarget as Image;
            var container:Container = img.parent as Container;
            container.removeChild(img);
            }
            }

            I'm thinking this _isn't_ actually going to do what the OP wants, as it's
            going to leave a bunch of empty containers all over the place. He should
            probably use a repeater and operate on the data source.

            JMO, of course.

            -Amy