A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Show/Hide multiple movieclips query

  1. #1
    Junior Member
    Join Date
    Nov 2009
    Posts
    6

    Show/Hide multiple movieclips query

    Hello,

    this is my first post here so please bear with me.

    I'd like to be able to have an array of movieclips where i'm able to toggle their visibility depending on what button has been pressed. I would need to have a default movieclip that is visible and all the others are hidden, but then when I click a button to make one of the other movieclips visible the default one is hidden etc.

    You can see an example of what i'm trying to achieve at http://www.blessthischick.com

    I'm experienced in PHP and HTML but have not used flash for several years so i'm pretty rusty. Can anyone point me in the right direction?

    Thanks,

    James

  2. #2
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    Hi and welcome

    is this example any help to you ? it is in AS2 (you haven't specified your version)

    PHP Code:
    cArr = [clip0clip1clip2]; // instance names of movieclips

    for(var a in cArr)cArr[a]._visible false// hide the array


    default_btn.onRelease = function(){ // instance name of button
    for(var a in cArr)cArr[a]._visible true// show the array
    };


    function 
    hideMC(clip){
    for(var 
    a in cArr)cArr[a]._visible false// hide all
    clip._visible true// show clicked clip
    default_btn._visible false// hide default
    }

    for(var 
    a in cArr){ // loop through array
    cArr[a].onRelease = function(){ // adding button events
    hideMC(this); 
    trace(this); // open output window - show which clip 
    };


  3. #3
    Junior Member
    Join Date
    Nov 2009
    Posts
    6
    Thanks for your reply a_modified_dog but it's not working like I need it to.

    I have attached some images below to hopefully explain.

    The movieclips are the pink circles. Each movieclip has a button assigned to it to make it visible only. When a different button is clicked it sets it's movieclip visible and all the others invisible.

    This is the default state when first loaded.



    If I click on button 2 the first movieclip is hidden and the second one is visible



    And so on...



    ...and on.



    Once the default state is invisible it should work just like the other buttons so if I clicked back on to button 1 the default movieclip (clip1) should be visible.




    Does this make more sense? I can get each button to turn its movieclip on and off ok but I have to do each one manually and this isn't what I need.
    Last edited by Giraffe Media; 11-11-2009 at 07:14 AM.

  4. #4
    Junior Member
    Join Date
    Nov 2009
    Posts
    6
    I have managed to get it working as I need it now, but I have had to apply code to each button and movie clip to show hide each mc. I could complete the project like this, but I may have over a hundred mc's in total so i'd rather use actionscript to control an array than have to attach it to each button/mc combination like I have done here.

    Any ideas.

    Regards

    James
    Attached Files Attached Files

  5. #5
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    seeing the images above, i used this code in a test file -
    PHP Code:
    btnArr = [btn1,btn2,btn33,btn56]; // note: button and clip instance
    clipArr = [clip1,clip2,clip33,clip56]; // names all end in numbers

    // hide all of the clips
    for(var a in clipArrclipArr[a]._visible false;

    // find number of clicked button 
    // so click button99, = return number 99 
    function extractNumber(str){
    var 
    str.lengthctmp "";
    for(var 
    aa=0aa<baa++){
    str.charAt(aa)
    if(
    c==parseInt(c)){ // if it is a number 
    tmp += c;
    }
    }
    return 
    parseInt(tmp); // return the number
    };

    for(var 
    d in btnArr){ // set button events
    btnArr[d].onRelease = function(){
    num extractNumber(this._name); // get the number
    for(var e in clipArrclipArr[e]._visible false// hide all clips
    this._parent["clip"+num]._visible true// add the number to the clip and show it
    }

    hope this helps

  6. #6
    Junior Member
    Join Date
    Nov 2009
    Posts
    6
    Quote Originally Posted by a_modified_dog View Post
    hope this helps
    It certainly did thanks very much. I had to add a line of code to get one of the clips visible by default, but apart from that it works like a treat!

    I have also tested duplicating the code, buttons and mc's and changing the array names and it works fine. Chances are I will need several arrays of 10+ items and this method is a very lightweight way of doing what I need. I was dreading having to hard code each button and mc!

    Thanks very much a_modified_dog, you've been a great help.

    James
    Last edited by Giraffe Media; 11-12-2009 at 05:34 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