dcsimg
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Controlling a movieclip added whit addChild()

  1. #1
    Member
    Join Date
    Oct 2000
    Posts
    43

    Controlling a movieclip added whit addChild()

    Hi:

    In my library I have a symbol.

    This symbol class is:

    xmx

    I export this symbol for actionscript.

    I export this symbol in the first frame.

    In the main time line i have a movielcip named: mc_mask

    Inside mc_mask I use this code to duplicate "xmx" movieclip inside "mc_mask" moveclip:

    * * * * * *
    BEGIN CODE
    * * * * * *
    var x_pos:int = 0;
    var y_pos:int = 0;

    var i:int;

    for(i=1; i<6; i++)

    {
    var new_img:xmx=new xmx();

    new_img.name="pic"+i;
    // set a name for the new movieclip

    new_img.x= x_pos;
    // set x position for the new movieclip

    new_img.y= y_pos;
    // set y position for the new movieclip

    x_pos += 20;
    // increment in 20 pixels the x position for the next movieclip

    addChild(new_img);
    }


    * * * * * *
    END CODE
    * * * * * *


    It works. It duplicates "xmx" movieclip inside "mc_mask"

    But..............


    I CAN NOT control the movieclips inside mc_mask...


    I have tried:

    a)
    mc_mask.pic1.alpha = .1;

    and does not work....


    b)
    mc_mask[pic1].alpha = .1;

    and does not work....


    c)
    mc_mask["pic1"].alpha = .1;

    and does not work....


    c)
    mc_mask['pic1'].alpha = .1;

    and does not work....

    d)
    pic1.alpha=.1;

    and does not work....

    Whe I publish my movie appears this error message:

    Error #1010: A term is undefined and has no properties



    How can I controll the movieclips CREATED WITH ACTION SCRIPT that are inside another movieclip?


    If I MANUALLY put an instance of "xmx" movieclip inside "mc_mask" movieclip and assign an instance name (for example pic1), I CAN CONTROL IT with:

    mc_mask.pic1.alpha = .1;

    But i want to add the "xmx" movieclip using ACTIONSCRIPT...


    Thank You in advance
    Last edited by albegago; 06-26-2009 at 11:19 PM. Reason: correction

  2. #2
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    mc_mask.getChildByName("pic1").alpha = .1;

  3. #3
    Member
    Join Date
    Oct 2000
    Posts
    43
    Thank You.

    With:

    mc_mask.getChildByName("pic1").alpha = .1;

    I can modify the properties of a movie.

    But how can I acces a method?

    Because:

    mc_mask.getChildByName("pic1").gotoAndPlay(20);

    DOES NOT WORK...

    When I use:

    mc_mask.getChildByName("pic1").gotoAndPlay(20);

    appears this error message:

    1061: Call to a possibly undefined method gotoAndPlay through a reference with static type flash.displayisplayObject.

    Thank You in advance

  4. #4
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    So because getChildByName() returns any child, the data type has to be DisplayObject (eg. it could return a textfield or a shape as well as MC or sprite) - so you need to manually tell the compiler what you expect to get back:

    PHP Code:
    MovieClip(mc_mask.getChildByName("pic1")).gotoAndPlay(20); 

Tags for this Thread

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