Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

getChildByName - Access a movieclip instance name inside

New Here ,
Jul 13, 2013 Jul 13, 2013

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?


TOPICS
ActionScript
1.4K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 14, 2013 Jul 14, 2013

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

Translate
Community Expert ,
Jul 13, 2013 Jul 13, 2013

use:

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



Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 13, 2013 Jul 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"

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 13, 2013 Jul 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 13, 2013 Jul 13, 2013

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

 

                              }

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 14, 2013 Jul 14, 2013

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 14, 2013 Jul 14, 2013

That did the trick! Awesome. Thanks!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 14, 2013 Jul 14, 2013
LATEST

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines