A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: help with simple play/pause button

  1. #1
    Member
    Join Date
    Apr 2002
    Posts
    81

    help with simple play/pause button

    I'm trying to make a single button both stop and play the movie. (I'm using setInterval to pause the movie at various points.) I'm trying to learn actionscript, so please excuse any terrible errors. (simple example file attached)

    First frame of movie:

    function pause(){
    play();
    clearInterval(timer);
    }
    playing=true;

    if (playing=true){
    playing!=false;
    }
    else if (playing!=true){
    playing=false;
    }

    On the button:

    on (release, keyPress "<Space>"){
    clearInterval(timer);
    if (playing=true){
    stop();
    playing!=true;
    }
    else if (playing=false){
    play();
    }
    }
    Attached Files Attached Files

  2. #2
    Senior Member
    Join Date
    Apr 2002
    Posts
    2,849
    Basically when you do an if statement, you want to use two equal signs. So

    if(playing==true){

    "!=" means "not equal to". Putting playing!=false doesn't really tell Flash anything. It's like me telling you my car isn't blue. Do you know now what color my car is?

    So instead of putting playing!=false, put playing=true.

    Enclosed is a Flash file with some minor adjustments that seems to work.
    Attached Files Attached Files

  3. #3
    Member
    Join Date
    Apr 2002
    Posts
    81
    Thanks so much for taking time to help me!

    The file you sent back seems to have one problem. The stop doesn't work when the playhead is already stopped on the setInterval frame. So I took out the playing=false from these frames and now it seems to work. Is that OK?

    Dennis

  4. #4
    Senior Member
    Join Date
    Apr 2002
    Posts
    2,849
    That's fine with me, it's up to you how you want to modify the file. I thought the intention of the button was to toggle, so if you click the button while it's stopped, it should start playing again. But again, modify to fit however you want it to work.

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