A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: mc to play until a certain frame is reached, then stop

  1. #1
    Junior Member
    Join Date
    Apr 2007
    Posts
    9

    mc to play until a certain frame is reached, then stop

    Hi, I'm hoping someone can help!

    I have an mc placed on the main stage that I'm trying to control through a separate button. I want the mc to play until a certain frame number is reached and then stop. I've got the following actionscript on the button instance:

    Code:
    on(rollOver){
    if (mc._currentframe == 10){
    mc.stop()
    }
    else{
    mc.play()
    }
    }
    This is not working at all - the mc is not stopping at frame 10, just looping continuously - am I missing something?

    Thanks for any help!

  2. #2
    :
    Join Date
    Dec 2002
    Posts
    3,518

    Maybe try something like this...

    The on rollOver code is only checking the status of the mc currentframe once, when the cursor moves over it. To keep checking it, until it reaches 10 use something like this...
    Code:
    on (rollOver) {
    	this.onEnterFrame = function() {
    		mc.play();
    		if (mc._currentframe == 10) {
    			mc.stop();
    			delete this.onEnterFrame;
    		}
    	};
    }

  3. #3
    Junior Member
    Join Date
    Apr 2007
    Posts
    9
    That works great, thanks!

  4. #4
    Junior Member
    Join Date
    Sep 2007
    Posts
    28
    thx a lot u have answered on my topic by this too

  5. #5
    Junior Member
    Join Date
    Jun 2009
    Posts
    12

    Play through to Cetain frame then stop in AS3 ???

    I am trying to basically do the same thing. I have a circle on my main timeline that rotates as the the timeline plays. I would like to have the timeline stop on a certain frame when a certain button is pressed. So basically, i would like to to a button to play through until it reaches a certain frame. It seems like the most basic thing, however, I cant do it.
    Help me FlashKit-Kenobi, you're my only hope..ok cheezy I know.
    Here is my code so far:

    green_btn.addEventListener(MouseEvent.CLICK, playGreen);

    function playGreen(event:MouseEvent):void
    {
    play()
    if (frame == 36) {
    stop();
    }


    }

  6. #6
    Flash/Flex Developer samac1068's Avatar
    Join Date
    Apr 2007
    Location
    Here, no there
    Posts
    1,813

    The easy way or the hard way.

    Quote Originally Posted by adrian7474 View Post
    I am trying to basically do the same thing. I have a circle on my main timeline that rotates as the the timeline plays. I would like to have the timeline stop on a certain frame when a certain button is pressed. So basically, i would like to to a button to play through until it reaches a certain frame. It seems like the most basic thing, however, I cant do it.
    Help me FlashKit-Kenobi, you're my only hope..ok cheezy I know.
    Here is my code so far:

    green_btn.addEventListener(MouseEvent.CLICK, playGreen);

    function playGreen(event:MouseEvent):void
    {
    play()
    if (frame == 36) {
    stop();
    }


    }
    You could just place a stop command on frame 36 of the timeline. This way you won't have to worry about it. If not, then you need an event listener to constantly check for current frame number. The event listener would be:
    PHP Code:
    stage.addEventListener(Event.ENTER_FRAMEcheckFrame);
    function 
    checkFrame(event:Event):void
    {
         if (
    MovieClip(parent).currentFrame == 36 )
         {
              
    stage.removeEventListener(Event.ENTER_FRAMEcheckFrame);
              
    MovieClip(parent).stop();
          }

    Some people are like Slinkies, not really good for anything, but they bring a smile to your face when pushed down the stairs.

  7. #7
    Registered User
    Join Date
    Apr 2015
    Posts
    1
    I have a timeline and i want to switch for particular frame number and want to play the tween animation at there
    And same thing at intervals but different frame no.

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