A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: How Do I Reference/Target the Child of an emptyMovieClip using an Array?

  1. #1
    Member
    Join Date
    Mar 2002
    Location
    Dayton, Ohio.
    Posts
    67

    How Do I Reference/Target the Child of an emptyMovieClip using an Array?

    Code:
    for (var menuItemNumber = 1; menuItemNumber<totalMenuItems; menuItemNumber++) {
    	_parent.createEmptyMovieClip("menuItem_"+menuItemNumber, _parent.getNextHighestDepth());
    	_parent["menuItem_"+menuItemNumber].createTextField("itemText_"+menuItemNumber, _parent.getNextHighestDepth);
    	_parent["menuItem_"+menuItemNumber]["itemText_"+menuItemNumber].text = "Test";
    }
    The above code in red does not work.

    Does anyone know the proper notation that will allow me to reference/target the .text attribute of any of the "itemText_"+menuItemNumber instances?

  2. #2
    Senior Member
    Join Date
    Feb 2005
    Posts
    149
    This small change:

    Code:
    _parent["menuItem_"+menuItemNumber].createTextField("itemText_"+menuItemNumber, _parent.getNextHighestDepth(),100+50*menuItemNumber,50,50,25);
    getNextHighestDepth()needs the "()" and add some x,y,width,height numbers.

  3. #3
    Member
    Join Date
    Mar 2002
    Location
    Dayton, Ohio.
    Posts
    67
    Originally posted by winterac
    This small change:

    Code:
    _parent["menuItem_"+menuItemNumber].createTextField("itemText_"+menuItemNumber, _parent.getNextHighestDepth(),100+50*menuItemNumber,50,50,25);
    getNextHighestDepth()needs the "()" and add some x,y,width,height numbers.
    Actually, my original code has such parameters, including the "()". I erased them as to make the code more concise.

    Regardless, populating those parameters still does not cause the code to work.

  4. #4
    Registered User nunomira's Avatar
    Join Date
    May 2002
    Location
    portugal
    Posts
    7,003
    hi berry_lthird,

    Your code may be correct...
    Make sure that the font color is not the same as the background color as you wouldn't see the text. Also, make sure that it's not another font problem.

    There are some things you can simplify, for example:
    code:

    for (var menuItemNumber = 1; menuItemNumber < totalMenuItems; menuItemNumber++)
    {
    var temp_mc = _parent.createEmptyMovieClip("menuItem_" + menuItemNumber, _parent.getNextHighestDepth());
    temp_mc.createTextField("someName", temp_mc.getNextHighestDepth(), 100 + 50 * menuItemNumber, 50, 50, 25);
    temp_mc.someName.text = "Test";
    }


    or just
    code:

    for (var menuItemNumber = 1; menuItemNumber < totalMenuItems; menuItemNumber++)
    {
    var temp_mc = _parent.createEmptyMovieClip("menuItem_" + menuItemNumber, _parent.getNextHighestDepth());
    temp_mc.createTextField("someName", 1, 100 + 50 * menuItemNumber, 50, 50, 25);
    temp_mc.someName.text = "Test";
    // make sure that everything is correct
    trace(temp_mc.someName);
    trace(temp_mc.someName.text);
    }


    You can use temp_mc because createEmptyMovieClip() returns a refence to the newly create movie clip. This simplifies writing target paths a lot.
    In the second line, you're creating a text field only inside the movie clip, so you can use a unique name like someName and you can even use a hardcoded value for its depth. In my opinion,
    _parent.getNextHighestDepth() doesn't make much sense, as you're targeting a different timeline from the one the text field is created in.
    Last edited by nunomira; 05-05-2005 at 05:02 AM.

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