dcsimg
A Flash Developer Resource Site

Results 1 to 11 of 11

Thread: Accessing children of getChildByName

  1. #1
    Senior Member ::bluemoth::'s Avatar
    Join Date
    Jun 2001
    Posts
    521

    Accessing children of getChildByName

    Does anybody know of a way to access a library MovieClip's children?
    I am adding instance of MovieClip to parent like so:
    Code:
    var legsArrow:MovieClip = new moreArrow();
    legsArrow.x = 0;
    legsArrow.y = 0;
    legsArrow.name = 'legsDirection';
    slides.addChild(legsArrow);
    I can then set library MovieClip instance x position like so:
    Code:
    slides.getChildByName('legsDirection').x = 10;
    However, I am having difficulty access a dynamic text field within the MovieClip:
    Code:
    slides.getChildByName('legsDirection').myText.text = 'newValue';
    slides.getChildByName('legsDirection').getChildByName('myText').text = 'newValue';

  2. #2
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,784
    Hi,

    Simply use legsArrow.myText.text = 'newValue';

    if you try this code in your page, you will see that legsDirectiom is actually called instance2( in my file anyway), so it bears no relevance to accessing the textfield with that name.

    PHP Code:
    if (legsArrow)
    {
        
    //trace('remove legsArrow');
        //slides.removeChild(legsArrow);
        
    legsArrow.myText.text 'newValue';
        
    slides.getChildByName('legsDirection').10;
        
        for(var 
    i:Number 0legsArrow.numChildreni++)
        {
            
    trace(legsArrow.getChildAt(i).name)
        }

    however you can access it like so

    PHP Code:
    this["slides"].getChildByName("legsDirection").myText.text "hello"
    you can also remove it like so
    PHP Code:
    this["slides"].removeChild(this["slides"].getChildByName("legsDirection")); 
    Last edited by fruitbeard; 04-04-2015 at 08:04 AM.

  3. #3
    Senior Member ::bluemoth::'s Avatar
    Join Date
    Jun 2001
    Posts
    521
    Hello again fruitbeard.

    This method doesn't work for me. I get error 1010 as soon as I try to access anything within the getChildByName("legsDirection") instance. Not sure why dot syntax doesn't work like a MovieClip authored on the stage, but it doesn't.

    I will try tracing the children and see if that helps get to the bottom of the problem.

  4. #4
    Senior Member ::bluemoth::'s Avatar
    Join Date
    Jun 2001
    Posts
    521
    I can trace the 'myText' child name, but I am struggling to reference it, so as to be able to alter the value:
    PHP Code:
    for(var u2:Number 0u2 legsArrow.numChildrenu2++){
        
    trace('Children: ' legsArrow.getChildAt(u2).name); // Children: myText
        
    this['slides'].getChildByName(legsDirection).myText.text 'hello';
        if(
    legsArrow.getChildAt(u2).name == 'myText'){
            
    legsArrow.getChildAt(u2).text 'hello';
        }

    Each reference I have tried always returns the child reference as undefined and has no properties, or is itself an undefined property.

    On the basis that legsArrow.getChildAt(u2).name returns 'myText' instance name of textfield, shouldn't one of the following work?
    PHP Code:
    slides.getChildByName(legsDirection).myText.text 'hello';
    legsArrow.getChildAt(u2).text 'hello'
    Last edited by ::bluemoth::; 04-05-2015 at 11:55 AM.

  5. #5
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,784
    Hi,

    Attach your *.fla ( or at least a slimmed down version ) and explain what it is you wish to achieve.

  6. #6
    Senior Member ::bluemoth::'s Avatar
    Join Date
    Jun 2001
    Posts
    521
    Thanks fruitbeard.

    I have uploaded a minimized version:
    http://goo.gl/JdkyHR

    The showSlideDirections function creates instances of moreArrow, which displays arrows at the top and bottom of each of the three main columns. At present, each column displays the first row of each column (all working good). The showSlideDirections function fades out the opacity of the arrows when that column cannot be moved further (all working good too).

    In addition to changing the arrows alpha, I am trying to add a numerical x of y status. To do this, I am trying to change the value of the moreText textfiled in the moreArrow moiveClip which is in the library. This is what is not working.

  7. #7
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,784
    Hi,

    unable to access the link, some sort of google nonsense about shortener.

    Upload one here, I'm pretty sure you should be able to figure it out from the previous posts though.

  8. #8
    Senior Member ::bluemoth::'s Avatar
    Join Date
    Jun 2001
    Posts
    521
    Attachment 75293File attached. I hadn't read the Google Policy about not linking straight to file.

  9. #9
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,784
    Hi,

    I can't really help you with that file. I don't have Flash CC, I don't have the tweenlite files, I don't really use AIR I,m sure if you go back over the earlier replies you can figure it out. Sorry.

  10. #10
    Senior Member ::bluemoth::'s Avatar
    Join Date
    Jun 2001
    Posts
    521
    Thanks for looking fruitbeard.

  11. #11
    Senior Member ::bluemoth::'s Avatar
    Join Date
    Jun 2001
    Posts
    521
    Got it.

    PHP Code:
    partArrow slides.getChildByName(legsDirection); // The unique child path
    partArrow.moreText.text '10'// Target child textfield 
    Thanks for your help fruitbeard.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center