A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: How do I make a button that will cycle through movie clip frames in AS3?

  1. #1
    Junior Member
    Join Date
    Dec 2013
    Posts
    1

    How do I make a button that will cycle through movie clip frames in AS3?

    For school, I'm making a dressup game. Now, I have posted my question to the professor---I go to school online---but he hasn't replied. I've been searching online for hours, and I just feel like tearing my hair out.

    Anyway, the Flash file is kinda big at this point, but let me show you what it looks like first:

    CASTLE_ball.jpg

    I've turned each of the blue things into buttons, added their instances, etc. And, I've made the movie clip stuff for the dresses. What I want it to do is to cycle through the movie clip when you press the button; no forward, no back; it just changes it to the next frame of the movie clip.

    Does ANYONE have a tutorial on this, or at least can point me in the right direction here? Everything I seem to have found is with AS2. -Sigh-

    Anyway, any help is appreciated. Cheers!

  2. #2
    Senior Member
    Join Date
    Nov 2012
    Posts
    106
    I don't know how much actionscript you know, but you could create a single function and add Event listeners to each of your movie clips. In my example, I just had one movieclip for the head with instance name of mcHead (with 5 different heads on their own frames) an another movie clip for the body with instance name of mcBody set up the same way, I did not have any stop(); actions inside the timelines, and so I had to stop with code. But if you have stop actions, then the first two lines after import statement are not necessary.

    Code:
     import flash.events.MouseEvent;
    mcHead.stop();
    mcBody.stop();
    mcHead.addEventListener(MouseEvent.CLICK, mcClicked);
    mcBody.addEventListener(MouseEvent.CLICK, mcClicked);
    
    function mcClicked(e:MouseEvent):void{
    	if(e.target.currentFrame==e.target.totalFrames){
    		e.target.gotoAndStop(1);
    	}else{
    	e.target.nextFrame();
    	}
    }
    The logic inside of the function handles the looping, so that once you reach the last frame, you go back to the first one.

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