A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: Music Player

Hybrid View

  1. #1
    Junior Member
    Join Date
    Jul 2015
    Posts
    9

    Music Player

    Hi
    I have come up against a problem that I hope someone can help me with I have 3 scenes I have a player with the usual stop start pause buttons.
    I have the player working fine on scene one but when I try to place the player on scene 2 I get error codes :
    How can I use music players on all scenes playing different sounds
    This is my code :

    import flash.events.MouseEvent;
    import flash.media.SoundChannel;


    var isPlaying:Boolean=false;
    var myMusic = new soothing();
    var myChannel:SoundChannel = new SoundChannel();
    var lastPosition:Number = 0;

    play_btn.addEventListener(MouseEvent.CLICK, onPlayClick);
    pause_btn.addEventListener(MouseEvent.CLICK, onPauseClick);
    stop_btn.addEventListener(MouseEvent.CLICK, onStopClick);

    function onPlayClick(event:MouseEvent):void{
    if(isPlaying==false){isPlaying=true;
    myChannel = myMusic.play(lastPosition)};

    myChannel.addEventListener(Event.SOUND_COMPLETE, completeHANDLER);
    function completeHANDLER(event:Event):void{
    lastPosition = 0;
    isPlaying=false}
    }

    function onPauseClick(event:MouseEvent):void{
    isPlaying=false;
    lastPosition = myChannel.position;
    myChannel.stop();
    }

    function onStopClick(event:MouseEvent):void{
    if(isPlaying==true){
    isPlaying=false;
    lastPosition = 0;
    myChannel.stop()}
    }

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

    What is soothing()?
    You need to change isPlaying for something else (maybe, isPlayed, all of them) or you will have namespace conflict errors.
    What other errors are you getiting.

    It might even help to attach your *.fla and other associated files, music files are not necessary though.

  3. #3
    Junior Member
    Join Date
    Jul 2015
    Posts
    9

    Music Player for scene one and two

    Quote Originally Posted by fruitbeard View Post
    Hi,

    What is soothing()?
    You need to change isPlaying for something else (maybe, isPlayed, all of them) or you will have namespace conflict errors.
    What other errors are you getiting.

    It might even help to attach your *.fla and other associated files, music files are not necessary though.
    Hi,
    I have attached the fla as you suggested You asked what is soothing This is one of two pieces of music mp3 . Basically what I want to do is have a music player on both scene one and two playing different music Any help you can give would be appreciated Many thanks
    Attached Files Attached Files

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

    Is there any particular reason for you to be using scenes?

    How are you getting to and from each scene? the file says nothing about this bit.

    Basically you have having errors with duplicate function names and namespace conflicts, if you rename the functions and vars difeerently for each scene the amount of errors with slowly drop.
    Last edited by fruitbeard; 07-09-2015 at 06:51 AM.

  5. #5
    Junior Member
    Join Date
    Jul 2015
    Posts
    9
    Quote Originally Posted by fruitbeard View Post
    Hi,

    Is there any particular reason for you to be using scenes?

    How are you getting to and from each scene? the file says nothing about this bit.

    Basically you have having errors with duplicate function names and namespace conflicts, if you rename the functions and vars difeerently for each scene the amount of errors with slowly drop.
    Hi
    What I will actually do once the music player is sorted will be make a new fla in air for andriod and use the swipe function to move backwards and forwards to the scenes with the swipe function

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

    Withiout messing around with your original code too much, you might find the first sound doesn't start sometimes, might just be me!
    Scene 1 code:
    PHP Code:
    import flash.events.MouseEvent;
    import flash.media.SoundChannel;

    var 
    playingScene1:Boolean false;
    var 
    musicScene1:Sound = new soothing();
    var 
    channelScene1:SoundChannel = new SoundChannel();
    var 
    positionScene1:Number 0;

    play_btn.addEventListener(MouseEvent.CLICKplayScene1);
    pause_btn.addEventListener(MouseEvent.CLICKpauseScene1);
    stop_btn.addEventListener(MouseEvent.CLICKstopScene1);

    function 
    playScene1(event:MouseEvent):void
    {
        if (! 
    playingScene1)
        {
            
    playingScene1 true;
            
    channelScene1 musicScene1.play(positionScene1);
        }
        
    channelScene1.addEventListener(Event.SOUND_COMPLETEcompleteScene1);
    }

    function 
    completeScene1(event:Event):void
    {
        
    positionScene1 0;
        
    playingScene1 false;
        
    channelScene1.removeEventListener(Event.SOUND_COMPLETEcompleteScene1);
        
        
    trace("Music scene 1 complete");
        
    gotoAndStop(1"Scene 2");
    }

    function 
    pauseScene1(event:MouseEvent):void
    {
        
    playingScene1 false;
        
    positionScene1 channelScene1.position;
        
    channelScene1.stop();
        
        
    trace(channelScene1.position);
    }

    function 
    stopScene1(event:MouseEvent):void
    {
        if (
    playingScene1)
        {
            
    playingScene1 false;
            
    positionScene1 0;
            
    channelScene1.stop();
        }
        
        
    trace(channelScene1.position);

    Scene 2 code:
    PHP Code:
    import flash.events.MouseEvent;
    import flash.media.SoundChannel;

    var 
    playingScene2:Boolean false;
    var 
    musicScene2:Sound = new warmsound();
    var 
    channelScene2:SoundChannel = new SoundChannel();
    var 
    positionScene2:Number 0;

    play_btn.addEventListener(MouseEvent.CLICKplayScene2);
    pause_btn.addEventListener(MouseEvent.CLICKpauseScene2);
    stop_btn.addEventListener(MouseEvent.CLICKstopScene2);

    function 
    playScene2(event:MouseEvent):void
    {
        if (! 
    playingScene2)
        {
            
    playingScene2 true;
            
    channelScene2 musicScene2.play(positionScene2);
        }
        
    channelScene2.addEventListener(Event.SOUND_COMPLETEcompleteScene2);
    }

    function 
    completeScene2(event:Event):void
    {
        
    positionScene2 0;
        
    playingScene2 false;
        
    channelScene2.removeEventListener(Event.SOUND_COMPLETEcompleteScene2);
        
        
    trace("Music scene 2 complete");
        
    gotoAndStop(1"Scene 1");
    }

    function 
    pauseScene2(event:MouseEvent):void
    {
        
    playingScene2 false;
        
    positionScene2 channelScene2.position;
        
    channelScene2.stop();
        
        
    trace(channelScene2.position);
    }

    function 
    stopScene2(event:MouseEvent):void
    {
        if (
    playingScene2)
        {
            
    playingScene2 false;
            
    positionScene2 0;
            
    channelScene2.stop();
        }
        
        
    trace(channelScene2.position);


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

    You will need to put the sounds back in the library in this file, smaller size for upload.

    fixed the first sound issue

  8. #8
    Junior Member
    Join Date
    Jul 2015
    Posts
    9
    Hi fruitbeard

    Thank you so much it works beautifully It was very generous of you to spend the time . I have studied your as3 script and now understand where I was going wrong Thanks once again Regards

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