A Flash Developer Resource Site

Page 1 of 9 12345 ... LastLast
Results 1 to 20 of 169

Thread: Buttons in down state... little help?

  1. #1
    Member
    Join Date
    Jul 2012
    Posts
    52

    Buttons in down state... little help?

    I'm a bit over my head with a slightly ambitious project I'm doing for a client who is a musician. The task is to create a fully functioning tape player. The problem I'm having is issues adapting button states, mostly the relation between the play and stop buttons.

    I've created all the images for the up and down states, but I'm not able to figure out the actions to actually get the tape player play button to stay down (on press) and play the mp3 songs.

    I also have the play button movie clip created with two states (up and down), but the actions I'm using aren't working the way I assumed they would. Am I missing something? It's been a while since I've used Flash for anything beyond roll overs... Below is the action I'm using for the play button:

    on (press) {
    }
    gotoAndStop(2);

    I have 3 songs the client has provided and assume having each song on a different scene would be the easiest way to do it with a click of the cassette tape to link to each scene.

    I've also created the spinning tape reel with a simple movie clip, but I'm also not sure the best way to speed it up and reverse it for fast forwarding and rewinding.

    The examples I've looked at online and on Youtube don't seem to relate, since in most cases the buttons aren't linked to each other and don't allow for a return to normal state for instance if the song is playing the play button would be in the down state, then return to up state when the stop button is pressed.

    Any help would be greatly appreciated.

  2. #2
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    actionscript Code:
    var pressed:Boolean;

    myButton.onPress=function(){
    if (pressed==true){           //if  button already pressed
    pressed=false;                //turn it unpressed and stop the music
    myMusic.stop();
    }
    else {                           //if not
    pressed=true;                //turn it pressed and play the music
    myMusic.start(0, 99)
    }

    }

  3. #3
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    Don't use Scenes. Is a bad idea. Better use frames. Example: Frame 1 you put a stop(); it stop at frame 1 and don't keep running. Then when pressing the button, go the 2nd frame or whatever frame you want.

  4. #4
    Member
    Join Date
    Jul 2012
    Posts
    52
    Thanks for the reply angelhdz, I'm assuming this action is being applied to the first frame of the movie clip. I have named this clip play button. It has two frames, with buttons on each frame (one of the up state and one down).

    Also how do I relate those buttons to fast forward and rewind while still allowing the play button to return to inactive state?

  5. #5
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    Also, if you want to unpress the "play" button when pressing the "stop" button you can do this
    actionscript Code:
    var pressed:Boolean;

    playButton.onPress=function(){
             if(this.pressed==true){
            //do nothing
    }  
    else {              
    playButton.pressed=true;                                      
    myMusic.start(0, 99)
    }
    };

    stopButton.onPress=function(){
         
    playButton.pressed=false;                                        
    myMusic.stop()

    }
    Explanation:

    On press the play button, if it is pressed , do nothing, because is already pressed, pressing it again won't do nothing. If is not pressed, it means you pressed the stop button, so, turn it pressed and play the music.

    On press the stop button, turn the play button unpressed, so you can play it again, and stop the music.

  6. #6
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    Here is the demo, to see if is what you need.
    You can't use regular buttons for this. You have to convert them to movieclip, assign instance name to them playButton, stopButtonand put Label names to the frames according to the button actions (UP, DOWN) And for the music, you have to assign an Identifier name in the linkage properties (Identifier in Flash CS6)
    For mine i used music and then i created the sound with
    Actionscript Code:
    myMusic=new Sound(); myMusic.attachSound("music");

    And in the first frame:
    Actionscript Code:
    var pressed:Boolean;

    myMusic=new Sound();
    myMusic.attachSound("music");

    playButton.onPress=function(){
             if(this.pressed==true){
            //do nothing
    }
    else {  
    playButton.gotoAndStop("DOWN");
    playButton.pressed=true;                                      
    myMusic.start(0, 99)

    }
    };


    stopButton.onPress=function(){
    this.gotoAndStop("DOWN");
         playButton.gotoAndStop("UP");
    playButton.pressed=false;                                      
    myMusic.stop()

    };
    stopButton.onRelease=stopButton.onReleaseOutside=function(){
        this.gotoAndStop("UP");
    };

    Let me know

    http://sofistica2.zzl.org/Yes.html
    Last edited by angelhdz; 07-17-2012 at 02:57 PM. Reason: script added

  7. #7
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    heres a bunch of code with play button and pause/unpause button with music loaded externally.

    Actionscript Code:
    played = "false";
    //play button
    button1.onPress = function()
    {
        stopAllSounds();
        Music = new Sound();
        //Music.attachSound("song1");//internal
        //Music.start(0,1);
        Music.loadSound("song1.mp3",true);//external
        played = "true";
    };
    //pause|unpause button
    button2.onPress = function()
    {
        if (played)
        {
            Music.stop();
        }
        else
        {
            Music.start(Music.position / 1000);
        }
        played = !played;
    };
    Last edited by fruitbeard; 07-17-2012 at 03:19 PM.

  8. #8
    Member
    Join Date
    Jul 2012
    Posts
    52
    I tried what you suggested, but it doesn't seem to be working. It just causes the buttons to move up and down.

    Here is a link to the fla zipped, maybe you could check it out and let me know what I'm doing wrong?

    http://www.sendspace.com/file/2300hd

  9. #9
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    Fruitbeard, your script is basically the same as mine, but loading the music externally, hehe. And in your code you didn't make the play button to stay "DOWN", which is what i think our friend Scrotin wanted, like a cassette player, you press PLAY and the button stays down/pressed. There is where i used
    Actionscript Code:
    playButton.gotoAndStop("DOWN");

    Scrotin, i'm looking to your fla. Give me some time.

  10. #10
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    I'm not competing with you Angel, but its more compact
    I didnt make a clip to do so (which is ever so easy), i was giving you a pause/unpause button.
    but to play from the paused position is the key element

    Scott are you going to be putting this on the web as its mighty huge file sizeand therefore loading the music externally would be advantageous, and the file you gave a link to is mighty mixed up
    Last edited by fruitbeard; 07-17-2012 at 04:55 PM.

  11. #11
    Member
    Join Date
    Jul 2012
    Posts
    52
    Scrotin, lol

    alright dude, thanks.

  12. #12
    Member
    Join Date
    Jul 2012
    Posts
    52
    Quote Originally Posted by fruitbeard View Post
    Hi,

    I'm not competing with you Angel, but its more compact
    I didnt make a clip to do so (which is ever so easy), i was giving you a pause/unpause button.
    but to play from the paused position is the key element

    Scott are you going to be putting this on the web as its mighty huge file sizeand therefore loading the music externally would be advantageous, and the file you gave a link to is mighty mixed up
    yeah, its going to be on the web. I noticed it was 118mb, not sure how to shrink that down without losing image quality. Do people still use pre loaders?

    I'm also not sure how to relate the fast forward to a sped up tape reel (movie clip) or to get it going clock wise at a faster speed to rewind...

  13. #13
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    just removing the embedded mp3 files would dramatically lower the file size, probably all of it actually, then load them externally
    the music would stream, very quickly with internet speeds nowadays

    //
    actually its not that big when compiled, but the music quality is at its lowest setting at present, if you make the music quality much better (which is what muso people want) then the file size increases lots

    as for the reel thingy, you could use _rotation at various speeds when told to, i really dont have lots of time at the moment, but i'm sure Angel will help you, i just jumped in, but can help at times
    Last edited by fruitbeard; 07-17-2012 at 05:14 PM.

  14. #14
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    lolllllll fruitbeard, i didn't said you are competing with me (i can't believe this)

    it was like "omg we both think in the same script", and then I pointed the fact that you forgot the button to stay "DOWN" when pressed, that was all.

    Scotin (sorry for the "scrotin" thing...i'm sleepy and tired working on my own projects)
    You can have your songs outside of flash, and load them externally like fruitbeard said, with loadSound(); so the FLA don't get heavier.

    just put your mp3's in the same location as your swf (flash movie) and call them like fruitbeard said

    Actionscript Code:
    myMusic1.loadSound("thisSong.mp3", true);

    Let's work in the main buttons issue first, then we work on the rewind/fastforward thing.
    Last edited by angelhdz; 07-17-2012 at 05:20 PM.

  15. #15
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    Scotin, do you have Flash cs3, cs4, or cs5?

  16. #16
    Member
    Join Date
    Jul 2012
    Posts
    52
    Scot is fine. I have CS4.

  17. #17
    Member
    Join Date
    Jul 2012
    Posts
    52
    Quote Originally Posted by fruitbeard View Post
    just removing the embedded mp3 files would dramatically lower the file size, probably all of it actually, then load them externally
    the music would stream, very quickly with internet speeds nowadays

    //
    actually its not that big when compiled, but the music quality is at its lowest setting at present, if you make the music quality much better (which is what muso people want) then the file size increases lots

    as for the reel thingy, you could use _rotation at various speeds when told to, i really dont have lots of time at the moment, but i'm sure Angel will help you, i just jumped in, but can help at times
    no worries, I appreciate your help. I actually took on this project to get up to date with action scripting and very quickly realized it wasn't going to be a simple up/down button kind of deal. I love working with this client though, so it's a matter of seeing it to the end whatever way possible.

  18. #18
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    Ok, if you give me time, this night i work on your proyect, and let it PRO. The only thing you have to do is change the myMusic.loadSound ("Your Song Here.mp3" ,true); name of your sound in the load sound first parameter, according to your song's file name. I've seen your FLA, and I know what to do. Also, as fruitbeard said, i will remove your reel animation in frames, and replace it with a simple actionscript rotation script. That will remove weight in your fla.

  19. #19
    Member
    Join Date
    Jul 2012
    Posts
    52
    wicked dude. if you wanna add me to msn or whatever send me a pm and we can battle through this. if you'd rather figure it out solo, that's cool too.

  20. #20
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971

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