Wednesday, September 12, 2007
I had a simple typo & that was causing all of this. Seemed silly that the below would have been true. Sorry. A true noob moment here.
I am plugging along
TypeError: Error #1010: A term is undefined and has no properties. at net.ericd.app::Application/::onClipLoaded()Hmmm. Kind of helpful, but I'd like it to be a little more verbose here. So I checked what was happening. I created three movieclips ahead of time and loaded content (SWFs) into them. These are then assigned to variables I can easily reference later, for calling methods, etc. However, if the clip is not on the displayList & you attempt to access anything within it/modify it, you get this error. What I was doing was making sure that the content loaded but was not yet displayed (not on displayList); I wanted contents within a clip resized & positioned correctly before adding to the displayList. Trying to access movieclips within the container that wasn't on the displayList barfed for me.
I would like to have the contents in that container set up ahead of time, so then I can just add it to the displayList and have it work... but I can't. might a solution be to addChild for it, set things up how I'd like & then remove it right away? That seems pretty hackish to me... or I can just set the things up AFTER I eventually add it to the displayList.
What is the best approach for something like this?
3 Comments:
-
said...
-
“You have a couple of options.
1) Use hasChild():
if(myClip.hasChild(myChildClip))
{
// gravy
}
else
{
// add child
}
2) A similar potential is to use try/catch. Syntax is like so:
try
{
// whatever code block you need. if any part of the code fails, proceed to catch.
}
catch($error1:Error)
{
// okay, there was an error above. let's try this code block.
}
catch($error2:Error)
{
// you can keep adding catches forever if you want.
}” -
Mike J said...
-
“By the way, not sure if you're using "MovieClip" in the generic sense as a container or not, but since switching to AS3 I haven't used a single proper MovieClip even once in an application.
I use Shape if I just need a drawing canvas ( like a decorator ) and Sprite if I need a container - they're much lighter weight and I can't think of many circumstances where I'd want something with an actual timeline of it's own anymore.
Even if you're loading a swf, you should be able to place it inside a Sprite as a container. =)” -
e.dolecki said...
-
“mike,
agreed. i changed that to Sprite right after i posted this stuff. i haven't used Shape yet, I've been using Sprite for that too.”







