Susan Day wrote:
On Wed, Feb 24, 2010 at 9:44 AM, Geografiek <[email protected]>wrote:
Well,
You could at least give a hint as to what _does_ work:
trace(my_obj.parent);
Thanks. That traced out the name of the class/*.as file, but when I put that
value in, as in:
MyClass.removeChild(my_obj);
it throws an error (1061). What do?
Susan,
Your tiny amounts of code hide the many reasons that you may be getting
errors.
I know others have made some suggestions but here are things to think about.
1)By convention classes are named with capital letters at the start,
instances with a lower case letter. This makes it easy to tell apart
classes from instance in the code.
When you write
MyClass.removeChild(my_obj);
It sets alarm bells ringing about whether you really mean what you write or are
simply not following coding conventions. In most cases it will result in an
error.
2) Classes that have parents must be descended from some kind of DisplayObject.
The obvious candidates are MovieClip and Sprite.
So to play around with parent, your class must extend MovieClip or Sprite or..
another class descended from DisplayObject.
We can't tell if you've done that.
3) The parent property will be null even after you've created a class instance
and will remain null until the instance is attached to a container of some form
such as a MovieClip, or Sprite or the stage.
addChild() will add a child instance to the "current" object (depends what
"this" is referring to and where your code is). This is not synonymous with adding
something to the stage, but may be.
Only when you have added an instance as a child will the parent property of the
instance be other than null.
So, plenty of ways to trip up, and with tiny code snippets and clear mistakes
you can see why everyone has to second guess what's going on.
Paul
With respect to Moock, yeah, got it, and it's the only reason I still
haven't pulled out all the hair in my head. Maybe get the cookbook too.
I think Mook is heavy for a first intro to OO and AS3 and I'd suggest
something lighter to get going.
Paul
TIA,
Susan
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders