A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: [F8] simple question..

  1. #1
    Member
    Join Date
    Dec 2006
    Posts
    43

    [F8] simple question..

    Hey everybody,

    Ok, i'm wondering if I can simplify and shorten my code.

    Currently, I have:
    Code:
    mc1.play();
    mc2.play();
    mc3.play();
    mc4.play();
    mc5.play();
    is there any way to simplify this by doing something along the lines of
    Code:
    mc1,mc2,mc3,mc4,mc5.play();
    I know this doesn't work, but i was wondering if there is a way to take tell multiple things to do the same action without having to write the command for each one seperately, or do an array or anything like that.

  2. #2
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    for(var n=1; n!=6;n++){
    this["mc"+n].play();
    }

  3. #3
    Member
    Join Date
    Dec 2006
    Posts
    43
    Hey you rock man, thx for helpin us all out here.

    That works, but it would only work for examples where all the movieclips are actually named like that.

    What if you want to click a button to stop multiple movieclips on the stage, but the names are not incremental like that? Would you have to type myMovie.stop(); for every movieclip or can you write one line of code that will stop multiple movies if they're names are totally different?

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

    Write a function to stop movies passed as the arguments.

    code:

    function stopMovies() {
    for (var i in arguments) {
    arguments[i].stop();
    }
    }

    stopMovies(movie1, anotherMovie, mov3);



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

  5. #5
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    and if u want to stop loads of movie clips but not write out their names then do:

    Code:
    stopAllMovies(_root); 
    
    function stopAllMovies(movie:MovieClip):Void {
    	movie.stop();
    	for (var i:String in movie) {
    		if (movie[i] instanceof MovieClip) {
    			movie[i].stop();
    			stopAllMovies(movie[i]);
    		}
    	}
    }
    the above example will stop all movieclips in the _root timeline (change this timeline according to your needs)
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

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