Skip to main content
Known Participant
July 13, 2013
Answered

getChildByName - Access a movieclip instance name inside

  • July 13, 2013
  • 1 reply
  • 1477 views

This works:

layerMenu.duplicateMov(LHolder.L1Holder, layerMenu.getChildByName("layer1"));

This doesn't work:

layerMenu.duplicateMov(LHolder.L1Holder, layerMenu.getChildByName("layer1").L0Dup);

L0Dup is an instance name of a movieclip inside getChildByName("layer1")

Any clues for a workaround?


This topic has been closed for replies.
Correct answer kglad

Error Message:

Scene 1, Layer 'Layer 1', Frame 1, Line 201119: Access of possibly undefined property L0Dup through a reference with static type flash.display:DisplayObject.

L0Dup is always visible, thus playing.

here is the function that creates "layer1" and more.

function createLayerBoxes()

                    {

                              for (var i:int = 0; i < NUM_LAYERS; i++)

                              {

                                        var box:Box = new Box( i + 1 );

                                        box.y = (box.height + LAYER_SPACING) * i;

                                        box.name= "layer" +( i + 1);

                                        box.buttonMode = true;

                                        box.addEventListener( MouseEvent.MOUSE_DOWN, onLayerPress );

                                        box.addEventListener( MouseEvent.MOUSE_UP, onLayerRelease );

 

 

 

                                        addChild( box );

                                        _boxes.push( box );

 

                              }


so, flash doesn't know you boxes can be displayobjectparent class objects.  if all the other potoential issues i listed in message 3 do not apply, use:

layerMenu.duplicateMov(LHolder.L1Holder, Box(layerMenu.getChildByName("layer1")).getChildByName("L0Dup"));

1 reply

kglad
Community Expert
Community Expert
July 13, 2013

use:

layerMenu.duplicateMov(LHolder.L1Holder, layerMenu.getChildByName("layer1").getChildByName("L0Dup"));



Rhov23Author
Known Participant
July 13, 2013

I've tried this, but it doesn't work. The L0Dup has the instance name from inside the library item which has AS linkage "Box"  , while "layer1" is from the array of "Box"

kglad
Community Expert
Community Expert
July 13, 2013

then you don't have a child of layerMenu.getChildByName("layer1") named "L0Dup" when that code executes or, if you see an error message, you may simply need to cast one or more objects.

so first, is there an error message?  if yes, what is it?

then, what is "layer1"? 

if that's not a movieclip instance name, that's the first error.  and, there may be more errors. 

if "laye1" is a child movieclip instance name and there is a child named "L0Dup" on "layer1"'s timeline, the frame that contains L0Dup needs to play before you can use that code.  in addition, no other frame of "layer1" that does NOT contain L0Dup can play.  ie, once L0Dup is created, it must continue to exist, at least, until that code referencing it executes.