Question

I have what seems to be a very simple issue. I need to create a shape and add it inside a movie clip that is inside of another movie clip.

The code I am currently using is as follows:

var enemy_beacon:Shape = new Shape();
fullmenu_mc.menu_map_mc.addChild(enemy_beacon);

fullmenu_mc.menu_map_mc.enemy_beacon.graphics.lineStyle(1, 0xFF0000, 1);
fullmenu_mc.menu_map_mc.enemy_beacon.graphics.beginFill(0xFFBB00,1);                            
fullmenu_mc.menu_map_mc.enemy_beacon.graphics.drawCircle(50, 50, 25);                                   
fullmenu_mc.menu_map_mc.enemy_beacon.graphics.endFill();

However, this code throws an Error #1010: A term is undefined and has no properties.

It seems to create the shape fine, but adding the shape (via addChild) or accessing any of its properties makes everything go haywire.

I already checked the instance names of the movie clips, everything is spelled correctly and nested correctly.

Any thoughts?

Was it helpful?

Solution

Since you have enemy_bacon instance, you can access it directly:

var enemy_beacon:Shape = new Shape();
fullmenu_mc.menu_map_mc.addChild(enemy_beacon);

enemy_beacon.graphics.lineStyle(1, 0xFF0000, 1);
enemy_beacon.graphics.beginFill(0xFFBB00,1);                            
enemy_beacon.graphics.drawCircle(50, 50, 25);                                   
enemy_beacon.graphics.endFill();

OTHER TIPS

The problem is that you don't give a name to your Shape.

fullmenu_mc.menu_map_mc doesn't know that your variable named enemy_beacon is the same that you've added to it's children.

Targeting children like that means that you are using their instance names. So fullmenu_mc.menu_map_mc.enemy_beacon means that you are searching a child called enemy_beacon inside menu_map_mc. And with the first two lines, you've just added some child to that menu item, but haven't specified name.

Instance names are not the same as your variables. Check this out:

var myShape:Shape = new Shape();
myShape.name = 'otherShape';
this.addChild(myShape); // you add specific item, name doesn't matter

trace (this.getChildByName('otherShape') == myShape); // you get child by NAME
// and because the child is the same as you've added, this will output: TRUE
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top