6 Replies Latest reply on Sep 25, 2008 9:18 PM by Merlyn_MM

    getChildIndex

    Merlyn_MM
      Here is my code but I am getting the following error.

      error 1118: Implicit coercion of a value with static type object to a possibly unrelated type flash.display:DisplayObject.

      What am I doing wrong? Can anyone help me please...


      private function categorysummaryselected(event:Event):void{
      var l:Label= new Label();
      l.text = "Hello";
      var idx:int = int(getChildIndex(event.currentTarget));
      Alert.show(idx.toString());
      myvbox.addChildAt(l,idx);
      }



      public function handleStringResult(event:ResultEvent):void{
      catInfo = event.result as ArrayCollection;
      var i = 1;
      for each(var o:Object in catInfo){
      var b:Button = new Button();
      b.label = o.FILLCOLOR;
      Alert.show(i);
      b.id=i;
      b.data=o.CATID;
      b.setStyle("fillColors",['#'+o.FILLCOLOR,'#'+o.FILLCOLOR]);
      b.setStyle("color","#FFFFFF");
      b.setStyle("fontFamily","Arial");
      b.setStyle("fontSize",8);
      b.setStyle("textRollOverColor", "red");
      b.addEventListener("click", myClickListener);
      b.addEventListener(MouseEvent.MOUSE_DOWN,categorysummaryselected);
      myvbox.addChild(b);
      i = i+1;
      }
      }
        • 1. Re: getChildIndex
          Level 7

          "Merlyn MM" <webforumsuser@macromedia.com> wrote in message
          news:gbgf53$cne$1@forums.macromedia.com...
          > Here is my code but I am getting the following error.
          >
          > error 1118: Implicit coercion of a value with static type object to a
          > possibly
          > unrelated type flash.display:DisplayObject.
          >
          > What am I doing wrong? Can anyone help me please...
          >
          >
          > private function categorysummaryselected(event:Event):void{
          > var l:Label= new Label();
          > l.text = "Hello";
          > var idx:int = int(getChildIndex(event.currentTarget));
          > Alert.show(idx.toString());
          > myvbox.addChildAt(l,idx);
          > }
          >

          Try
          var do:DisplayObject = event.currentTarget as DisplayObject
          var idx:int;
          if (do) {
          idx = getChildIndex(event.currentTarget);
          } else {
          idx = numChildren;
          }

          HTH;

          Amy


          • 2. Re: getChildIndex
            Gregory Lafrance Level 6
            Here is a complete example. BTW, you need to call myvbox.getChildIndex():
            • 3. Re: getChildIndex
              Merlyn_MM Level 1
              Awesome! this worked. And also is there a way to remove all the children of all the buttons before adding the new child?

              Thanks!
              • 4. Re: getChildIndex
                Gregory Lafrance Level 6
                If you mean delete the button that was clicked to add the label:
                • 5. Re: getChildIndex
                  Level 7
                  If you mean delete the button that was clicked to add the label:


                  private function categorysummaryselected(event:Event):void{
                  var btn:Button = event.currentTarget as Button;
                  var l:Label= new Label();
                  var idx:int = int(myvbox.getChildIndex(event.currentTarget as Button));
                  l.text = "Hello" + idx;
                  Alert.show(idx.toString());
                  myvbox.removeChild(btn);
                  myvbox.addChildAt(l,idx);
                  }

                  • 6. Re: getChildIndex
                    Merlyn_MM Level 1
                    I meant removing the children of the buttons before adding a new child(label in this case). Sorry for not being clear.

                    Thanks