Search code examples
actionscript-3flashactionscriptmovieclipaddchild

AS3: A term is undefined when adding a shape inside a movieclip


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?


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();