3 Replies Latest reply on Aug 2, 2009 6:55 AM by SiHoop

    Creating multiple instances of a class

    SiHoop Level 1

      The function below is used to draw graphics on a series of instances stored in mcArray. One of the graphics I draw is a checkmark that should get added to correct answers using: mcArray[t].addChild(pictLdr.content);

      My problem is that only one instance of the class is created-- nthe last one. All the others are removed. I assume that I should be creating more instances of the class, but I'm not sure where I should be doing this. Any advice would be much appreciated!

      Thank you.

       

          public function giveFeedback(answersArray:Array):void{
              pictLdr = new Loader();
              var pictURL:String = "../pics/checkmark_green.png"
              var pictURLReq:URLRequest = new URLRequest(pictURL);
              pictLdr.load(pictURLReq);
              pictLdr.contentLoaderInfo.addEventListener(Event.COMPLETE, imgLoaded);
              function imgLoaded(e:Event):void{
              for(var t:int=1;t<mcArray.length;t++){//Loop through the movieclips in the array
                      for(var tt:int=0;tt<mcArray[t].numChildren;tt++){//Loop through each of the children in each movieclip
                          if(mcArray[t].getChildAt(tt).name=="clickLine"){//If a movieclips is named 'clickline', draw the graphics as follows:
                              if(answersArray[t]==1){//right answer
                                  mcArray[t].getChildAt(tt).graphics.beginFill(0x81c92e)
                                  mcArray[t].getChildAt(tt).alpha=0
                                  Tweener.addTween(mcArray[t].getChildAt(tt), {alpha:1, time:.5, transition:"easeOutSine"});
                                  mcArray[t].addChild(pictLdr.content);
                              }else if (answersArray[t]==2){//wrong answer
                                  mcArray[t].getChildAt(tt).graphics.beginFill(0xea4235)
                                  mcArray[t].getChildAt(tt).alpha=0
                                  Tweener.addTween(mcArray[t].getChildAt(tt), {alpha:1, time:.5, transition:"easeOutSine"});
                              }//Now draw the graphics
                              mcArray[t].getChildAt(tt).graphics.drawRect(12,-5, 5, 40);
                              mcArray[t].getChildAt(tt).graphics.endFill()
                             
                          }           
                      }   
                  }
              }       
          }