dcsimg
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: [F8] applying the same action to multiple movieclips

  1. #1
    Junior Member
    Join Date
    Jun 2005
    Location
    England
    Posts
    26

    [F8] applying the same action to multiple movieclips

    Hi there,

    I have a movieclip with loads of instances of the same button inside of it. Each instance name is different, i.e. one might be jeff, the other john another dan etc.

    I want to apply the same actions to each instance within the movieclip, but don't really want to have to write the code out again and again e.g.

    myMC.jeff.onRelease = function(){
    //code goes here
    }

    myMC.john.onRelease = function(){
    //code goes here
    }

    etc.

    Is there a way to find out all the instances within a movieclip and give them all the same code?

    Cheers,

    Bob
    info@bobcooper.org.uk
    www.bobcooper.org.uk

  2. #2
    All 1s and 0s dmonkey's Avatar
    Join Date
    Nov 2005
    Location
    Leeds, UK
    Posts
    606
    Hi,

    You can access child clips of a movieclip in much the same way as you would with an array. Use the for ... in statement.

    code:

    for (child in myClip) {
    //Check that it is a movieClip
    if (myClip[child] instanceof MovieClip) {
    //Perform actions on it
    myClip[child].stop();
    }
    }



    Hope this helps.
    "If I have seen further, it is by standing on the shoulders of giants." - Sir Isaac Newton

  3. #3
    Member
    Join Date
    Dec 2005
    Posts
    99
    I am trying the same thing, only the actions that I am applying are motion tweens. Can anybody help with this code?

    code:


    for (child in NewsItems) {
    //Check that it is a movieClip
    if (NewsItems[child] instanceof MovieClip) {
    //Perform actions on it
    function over () {
    var tw:Tween = new Tween(NewsItems[child],"_xscale",Strong.easeOut,NewsItems[child]._xscale,NewsItems[child]._xscale+5,0.5,true);
    var tw2:Tween = new Tween(NewsItems[child],"_yscale",Strong.easeOut,NewsItems[child]._yscale,NewsItems[child]._yscale+5,0.5,true);
    }

    function out () {
    var tw:Tween = new Tween(NewsItems[child],"_xscale",Strong.easeOut,NewsItems[child]._xscale,NewsItems[child]._xscale-5,0.5,true);
    var tw2:Tween = new Tween(NewsItems[child],"_yscale",Strong.easeOut,NewsItems[child]._yscale,NewsItems[child]._yscale-5,0.5,true);
    }
    NewsItems[child].onRollOver = over;
    NewsItems[child].onRollOut = out;
    }
    }


    Last edited by Pants234; 05-29-2007 at 09:30 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