PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
controlcontinuous music through scenes
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: controlcontinuous music through scenes

  1. #1
    Junior Member
    Join Date
    Feb 2011
    Posts
    11

    controlcontinuous music through scenes

    I have a movie clip called player where there is a code to pull a background music through an xml file. In the same movie clip, there is play and pause controls. Here's the code:

    Actionscript Code:
    stop();

    var my_songs:XMLList;
    var my_total:Number;

    var my_sound:Sound;
    var my_channel:SoundChannel;

    var current_song:Number = 0;

    var song_position:Number;
    var song_paused:Boolean;

    var myXMLLoader:URLLoader = new URLLoader();
    myXMLLoader.load(new URLRequest("playlist.xml"));
    myXMLLoader.addEventListener(Event.COMPLETE, processXML);

    function processXML(e:Event):void {
        var myXML:XML = new XML(e.target.data);

        my_songs = myXML.SONG;
        my_total = my_songs.length();

        playSong(0);

        myXMLLoader.removeEventListener(Event.COMPLETE, processXML);
        myXMLLoader = null;

    }

    function playSong(mySong:Number):void {
        var myURL = my_songs[mySong].@URL;
        if (my_channel) {
            my_channel.stop();
        }

        my_sound = new Sound();
        my_sound.load(new URLRequest(myURL));
        my_channel = my_sound.play();
       
    }

    pausar.addEventListener(MouseEvent.CLICK, onPause);
    function onPause(e:MouseEvent):void {
        music_bars.stop();
        if (my_channel) {
            song_position = my_channel.position;
            my_channel.stop();
            song_paused=true;
           
        }
    }
    tocar.addEventListener(MouseEvent.CLICK, onPlay);
    function onPlay(e:MouseEvent):void {
        music_bars.play();
        if (song_paused) {
            my_channel = my_sound.play(song_position);
            song_paused=false;
        } else if (!my_channel) {
            playSong(current_song);
        }
    }

    I put this movie clip in the first scene and the music continues when I change the scene. So far so good. But if I put the movie clip in the other scenes, to control the music on the scene, the music resumed and the first music never stops.

    How can I fix this?

  2. #2
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    For controlling audio the best is to use a Singleton.

    http://flashscript.biz/Flash10/inshort/PlayOneSound.php
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

  3. #3
    Junior Member
    Join Date
    Feb 2011
    Posts
    11
    Thanks!

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