-
create movieclip in anothher class
Hi everybody...
I'm pretty new in AS3...
In class A I write
Actionscript Code:
[...] public class A extends MovieClip { public function A():void {
public static var menuContainer:MovieClip; menuContainer = new MovieClip(); addChild (menuContainer); menuContainer.y = 200 [...]
In class B I write
Actionscript Code:
[...] var p:menuItem_mc = new menuItem_mc() Main.menuContainer.addChild (p) [..]
And this works fine.
But I would like to move all the code belonging to the menu to class B...
so I commented all the code above in class A and in class B I wrote:
Actionscript Code:
var p:menuItem_mc = new menuItem_mc() var Main.menuContainer:MovieClip; Main.menuContainer.addChild (p)
but I got the following error:
TypeError: Error #1010: A term is undefined and has no properties.
at Menu$/deployMenu()
So...my question is: how can I create a movieclip in another class and add a child to it?
thanks,
Adam
-
There is a lot wrong with the code you posted. It shouldn't work at all. You've got a public static variable declared inside the constructor for A. That shouldn't be valid.
Anyway. You cannot declare variables/properties in one class from another. Nor should you need to. If A was dynamic, you could add an arbitrary property to an instance of A at runtime, but not a static property to A itself.
What you should be doing here is creating a Menu class, then create an instance of that Menu in B. Prepare the Menu instance with any menuItems you need to, then you can use addChild to add the instance of Menu to any other DisplayObjectContainer instance. I'd suggest adding it to your instance of B since B seems to know everything about and require the menu. But if your instance of B has a reference to an instance of A, you could add the menu to that.
-
Originally Posted by 5TonsOfFlax
There is a lot wrong with the code you posted. It shouldn't work at all. You've got a public static variable declared inside the constructor for A. That shouldn't be valid.
Anyway. You cannot declare variables/properties in one class from another. Nor should you need to. If A was dynamic, you could add an arbitrary property to an instance of A at runtime, but not a static property to A itself.
What you should be doing here is creating a Menu class, then create an instance of that Menu in B. Prepare the Menu instance with any menuItems you need to, then you can use addChild to add the instance of Menu to any other DisplayObjectContainer instance. I'd suggest adding it to your instance of B since B seems to know everything about and require the menu. But if your instance of B has a reference to an instance of A, you could add the menu to that.
Yep...got it.
Thanks for helping
Tags for this Thread
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
|