4 Replies Latest reply on Aug 17, 2006 12:12 AM by AlexInd

    problem in returning value of getChildByName

    AlexInd
      Hi everybody,
      i have been facing a big problem. I am working in AS3 in which i wrote a file in AS which i named as cell.as (extending cell as MovieClip) and i declared a user define boolean variable called startUp:Boolean; and i wrote another AS file in which I reffered that cell.as as newCell:new cell() and made a grid of 5x5. the problem is that whenever i traced the value, simply when created a new instance,say txt.text=(newCell.startUp).toString(); (where txt is textField), i get the value (either true or false) according to my setting but if i when used the code like this:
      for(i=1;i<=5;i++){
      for(j=1;j<=5;j++){
      var newCell:cell=new cell(20,20,"newCell"+i+j);
      newCell.name="newCell"+i+i;
      this.addChild(newCell);
      if(i==3 && j==2){
      txt.text=((newCell.parent.getChildByName("newCell"+i+j)).startUp).toString();
      }
      }
      }


      i got an error as: use of undefined property, startUp .
      Why?

      Is the returning value of the getChildByName ( ) does not support any user define properties (variables).


      Any comments will be helpful.
      Regards,
      Alexson
        • 1. Re: problem in returning value of getChildByName
          inlineblue Level 1
          getChildByName() returns a DisplayObject, which has no startUp field. You'll need to cast the object in order to use it as a cell. eg:

          var child: Object = newCell.parent.getChildByName("newCell"+i+j);
          var mycell: cell = cell(child); //Cast it
          txt.text = mycell.startUp.toString();
          • 2. Re: problem in returning value of getChildByName
            AlexInd Level 1
            Thanks, inlineBlue
            I further want to know if i want to change the value of startUp which is a boolean type( user define, in the actionscript file, cell.as, i had created) for movieClip instance, (created earlier),....... lets say the current focussed movieClip is newCell51 when clicking on it the value of the startUp(boolean type) for movieClip(newCell41)which is just above the current focussed movieClip (newCell51) be changed.....such that if the value of startUp in newCell is "false" then it should be "true" and when clicking on the next focussed movieClip(newCell41) the value of startUp for the movieClip(newCell31) be changed........so on....
            Thanks


            Regards,
            Alexson
            • 3. Re: problem in returning value of getChildByName
              peterent Level 2
              There's something else to be aware of, although in the code you have it may not be a problem.

              When you do: cell = new Cell(); addChild(cell); the parent-child relationship is created (eg, cell.parent) but none of the UI, including measurement and layout has occured. So if your startUp method contains any references to the UI elements of cell or requires the parent to know where cell is, it won't work.

              You need to give the Flex framework time to go through its tasks. Use events like creationComplete to let you know when the UI is ready.

              As I said, this may not be a problem, but something to keep an eye on.
              • 4. problem in returning value of getChildByName
                AlexInd Level 1
                Thanks inLineBlue and Peterent and Brajeshwar ....your coments help me solve my problem...now i can understand things little bit...
                When i cast the returned value, object , by getChildByName ( ) method, like the following code, I got my solution:-
                (cell(this.getChildByName("newCell"+(i-1)+j))).startUp=true;
                Thanks once more.

                Regards,
                Alexson