Wednesday, September 12, 2007
as3 find: TypeError #1010. best practice?
Wednesday, September 12, 2007
UPDATE: MORON ALERT!!!
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 alongjust fine with AS3 so far & loving a lot of it. This discovery phase is pretty fun, stumbling to find AS2-like matches and utilizing a lot of new stuff is proving to be pretty exciting. A great way to learn instead of simply reading something somewhere or copy&paste. Anyway, I am loading assets into my main document class, and came across something interesting that I saw some coverage about online, but what I read didn't quite match with what I was experiencing.
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?
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?
Comments:
There are currently 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.
}”



