A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: Can't access dynamic field in nested clip

  1. #1

    Can't access dynamic field in nested clip

    I have this part working:

    PHP Code:
        for (i=0i<5i++) {
          
    myMovie.addChild(myClip);
          
    myMovie.getChildAt(i).i;

    each myMovie contains a nested clip (nestedClip) which, in turn, contains a nested, dynamic text field (myField).

    I'm trying to set the text fields as I create new clips. This next code block is the same as above, but adds the line where I try to change the text field:
    PHP Code:
        for (i=0i<5i++) {
          
    myMovie.addChild(myClip);
          
    myMovie.getChildAt(i).i;
          
    myMovie.getChildAt(i).nestedClip.myField.text "hello";  // <---new line

    that code produces this error:
    1119: Access of possibly undefined property nestedClip through a reference with static type flash.display: DisplayObject.

    What am I doing wrong??
    Last edited by Ideasite; 01-28-2009 at 01:41 PM.

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    What am I doing wrong??
    Not reading error messages.

    getChildAt returns a DisplayObject. DisplayObjects don't have a nestedClip property.

    To hint to the compiler that you know better than it does about the types, you can cast:
    Code:
          myMovie.addChild(myClip);
          myMovie.getChildAt(i).x = 5 * i;
          MovieClip(myMovie.getChildAt(i)).nestedClip.myField.text = "hello";
    Of course, you don't have to get it with getChildAt in the first place since you already have it

    Code:
          myMovie.addChild(myClip);
          myClip.x = 5 * i;
          myClip.nestedClip.myField.text = "hello";

  3. #3
    Your suggestion worked! I'm still struggling to understand it completely.

    AS3 definitely adds an entire additional layer to the outside of everything compared to AS2. I'm still grappling with it all.

    Thanks for the quick reply!

  4. #4
    I use names like myMovie_mc in order to see the code hinting. Will avoiding the _mc also stop the compiler from complaining?

  5. #5
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    No, the compiler doesn't care what names you use as long as they are valid names. "_mc" is not in any way magic.

    For that matter, it shouldn't affect code hinting either. I'm not sure I get what you're saying.

  6. #6
    The docs say that code hinting pops up if the names you give objects end in their abbreviated type: _mc _btn _txt, etc. It does display a box of appropriate choices, but it's getting irritating. In fact, I had already done a similar thing to this but didn't get an error message and the only difference was that the name of this clip ended in _mc and that one did not.

    Adobe doesn't seem to have gone out of their way to make AS3 easy to master.

  7. #7
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Oh, I don't use flash for editing, so I don't know what sort of code hinting it does. It seems really weird that it would be based on naming convention rather than actual type like all other editors I know of.

  8. #8
    What do you use? I'm on a Mac and have used BBedit and Coda. Adobe should really fix the text editor. It doesn't even auto wrap.

    Have you heard anything about FlashCatalyst or Gumbo? They're both new development tools by Adobe - both in beta:

    http://labs.adobe.com/technologies/flashcatalyst/
    http://labs.adobe.com/technologies/gumbo/

    Sounds interesting

  9. #9
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    I use FlashDevelop on Windows. Haven't really looked into catalyst or gumbo.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center