A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Multiple swf's previewing mp3

  1. #1
    Junior Member
    Join Date
    Nov 2010
    Posts
    3

    Multiple swf's previewing mp3

    Hello everyone!

    (this is my first post here )

    I am developing a flash preview in Flash 10. Publish settings: Flash Player 8, Actionscript 1.

    I call the file preview.swf and it takes FlashVars in a for-each loop in php to get the correct ID of the mp3.

    It works perfectly fine to play an mp3 and stop it and then play again. The two problems I run into is:
    1. When/if I play an swf the mp3 starts playing and the stop button becomes visible. If I wait until the sound has completetd the swf transforms back to the play button but now I cannot play that specific sound again!
    2. I need to stop/reset every other swf preview when I play one of the swf's. This is because I don't want the user to have to first click stop on the currently playing swf before he can listen to ONLY the one he presses play on.

    Here is the code:
    AS frame:
    onClipEvent (load)
    {
    //var songId = 100;
    myMusic = new Sound();
    myMusic.loadSound(_root.songId+".mp3");
    _root.loadBar._xscale = 0;
    myMusic.onLoad = function ()
    {
    myMusic.start();
    _root.playing = 1;
    _root.percentLoadedTextt._visible = 0;
    gotoAndStop(1);
    };
    myMusic.onSoundComplete = function ()
    {
    _root.playing = 0;
    _root.paused = 1;
    _root.loadMovie("preview.swf", 0);
    };
    if (_root.playing != 1)
    {
    _root.playing = 1;
    _root.paused = 0;
    if (_root.mySoundPosition == nul)
    {
    _root.mySoundPosition = 0;
    } // end if
    _root.myMusicMc.myMusic.start(_root.mySoundPositio n, 0);
    gotoAndStop(1);
    } // end if
    }
    onClipEvent (enterFrame)
    {
    mySoundBytesTotal = myMusic.getBytesTotal();
    mySoundBytesLoaded = myMusic.getBytesLoaded();
    mySoundLoading = Math.round(mySoundBytesLoaded / mySoundBytesTotal * 100);
    if (mySoundLoading != null)
    {
    _root.percentLoadedText = mySoundLoading + "";
    } // end if
    _root.loadBar._xscale = mySoundLoading;
    _root.myMusicDurationText = myMusic.duration / 1000;
    _root.myMusicPositionText = myMusic.position / 1000;
    if (_root.playing == 1)
    {
    _root.paused = 0;
    _root.playButton._visible = 0;
    _root.pauseButton._visible = 1;
    } // end if
    if (_root.paused == 1)
    {
    _root.playing = 0;
    _root.playButton._visible = 1;
    _root.pauseButton._visible = 0;
    gotoAndStop(1);
    } // end if
    }

    Play button:
    on (press)
    {
    _root.mySoundPosition = _root.myMusicMc.myMusic.position / 1000;
    _root.paused = 1;
    _root.playing = 0;
    _root.playing = 0;
    _root.playButton._visible = 1;
    _root.pauseButton._visible = 0;
    gotoAndStop(1);

    gotoAndStop(2);
    }

    Stop button:
    on (press)
    {
    _root.myMusicMc.myMusic.stop();
    _root.mySoundPosition = _root.myMusicMc.myMusic.position / 1000;
    _root.paused = 1;
    _root.playing = 0;
    _root.playing = 0;
    _root.playButton._visible = 1;
    _root.pauseButton._visible = 0;
    gotoAndStop(1);
    }

    PLEASE SOMEONE HELP!!

    Kindest regards Joel

  2. #2
    Member
    Join Date
    Sep 2009
    Posts
    57
    Let me get this straight. You are trying to play a specific song on a specific movie, correct?

    You are publishing this in flash 8. This is your AS1 code.

    Actionscript Code:
    onClipEvent (load) {
        //var songId = 100;
        myMusic = new Sound();
        myMusic.loadSound(_root.songId + ".mp3");
        _root.loadBar._xscale = 0;
        myMusic.onLoad = function()
        {
            myMusic.start();
            _root.playing = 1;
            _root.percentLoadedTextt._visible = 0;
            gotoAndStop(1);
        };
        myMusic.onSoundComplete = function()
        {
            _root.playing = 0;
            _root.paused = 1;
            _root.loadMovie("preview.swf", 0);
        };
        if (_root.playing != 1)
        {
            _root.playing = 1;
            _root.paused = 0;
            if (_root.mySoundPosition == nul)
            {
                _root.mySoundPosition = 0;
            }
            // end if
        }
        _root.myMusicMc.myMusic.start(_root.mySoundPosition,0);
        gotoAndStop(1);
    }// end if
    onClipEvent (enterFrame) {
        mySoundBytesTotal = myMusic.getBytesTotal();
        mySoundBytesLoaded = myMusic.getBytesLoaded();
        mySoundLoading = Math.round(mySoundBytesLoaded / mySoundBytesTotal * 100);
        if (mySoundLoading != null)
        {
            _root.percentLoadedText = mySoundLoading + "";
        }
        // end if
        _root.loadBar._xscale = mySoundLoading;
        _root.myMusicDurationText = myMusic.duration / 1000;
        _root.myMusicPositionText = myMusic.position / 1000;
        if (_root.playing == 1)
        {
            _root.paused = 0;
            _root.playButton._visible = 0;
            _root.pauseButton._visible = 1;
        }
        // end if
        if (_root.paused == 1)
        {
            _root.playing = 0;
            _root.playButton._visible = 1;
            _root.pauseButton._visible = 0;
            gotoAndStop(1);
        }
        // end if
    }

    //Play button:
    on (press) {
        _root.mySoundPosition = _root.myMusicMc.myMusic.position / 1000;
        _root.paused = 1;
        _root.playing = 0;
        _root.playing = 0;
        _root.playButton._visible = 1;
        _root.pauseButton._visible = 0;
        gotoAndStop(1);

        gotoAndStop(2);
    }

    //Stop button:
    on (press) {
        _root.myMusicMc.myMusic.stop();
        _root.mySoundPosition = _root.myMusicMc.myMusic.position / 1000;
        _root.paused = 1;
        _root.playing = 0;
        _root.playing = 0;
        _root.playButton._visible = 1;
        _root.pauseButton._visible = 0;
        gotoAndStop(1);
    }

    Now, do I have all the facts cleared up?

  3. #3
    Junior Member
    Join Date
    Nov 2010
    Posts
    3
    i use 1 swf file for all mp3 previews; "preview.swf" and not one for each mp3. preview.swf takes in the variable "songId".

    everything else is correct

  4. #4
    Junior Member
    Join Date
    Nov 2010
    Posts
    3
    help someone??...

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