-
Can't access dynamic field in nested clip
I have this part working:
PHP Code:
for (i=0; i<5; i++) {
myMovie.addChild(myClip);
myMovie.getChildAt(i).x = 5 * 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=0; i<5; i++) {
myMovie.addChild(myClip);
myMovie.getChildAt(i).x = 5 * 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.
-
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";
-
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!
-
I use names like myMovie_mc in order to see the code hinting. Will avoiding the _mc also stop the compiler from complaining?
-
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.
-
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.
-
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.
-
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
-
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|