Visualizzazione dei risultati da 1 a 2 su 2
  1. #1
    Utente di HTML.it
    Registrato dal
    Feb 2008
    Messaggi
    21

    [as3] Modificare script musica di sottofondo

    Salve a tutti. Chiedo aiuto!
    Mi sono imbattuto in questo codice e stavo cercando di modificarlo.

    http://blog.0tutor.com/post.aspx?id=...Actionscript-3

    Riporto il codice.

    Codice PHP:
    //attatch/import the music file.  
    var musicPiece:Sound = new Sound(new URLRequest("010.MP3"));

    // Make a sound channel to change sound configurations.
    var mySoundChannel:SoundChannel;

    // This variable is checking if the music is playing
    var isPlaying:Boolean false;

    // to remember the position of the music playing when we pause, _ 
    to start at the same place


    var pos:Number 0;

    // First button we will make is a play button, add an eventlistener.
    play_btn.addEventListener(MouseEvent.CLICKplay_);

    function 
    play_(event:Event):void {
    //Check if the music is NOT playing, then make it start.
    if (!isPlaying) {
    mySoundChannel musicPiece.play(pos);
    isPlaying true;
    }
    }

    // The pause button, here we will use the pos variable we made earlier.
    pause_btn.addEventListener(MouseEvent.CLICKpause_);

    function 
    pause_(event:Event):void {
    // if the music is player, save the current time and stop the playing.
    if (isPlaying) {
    pos mySoundChannel.position;
    mySoundChannel.stop();
    isPlaying false;
    }
    }

    // Now the final button is the stop button, allmost thet same as pause
    stop_btn.addEventListener(MouseEvent.CLICKstop_);

    function 
    stop_(event:Event):void {
    // First we check if there is anything to stop then make it stop, and reset the pos variable to 0 (start time)
    if (mySoundChannel != null) {
    mySoundChannel.stop();
    pos 0;
    isPlaying false;
    }
    }

    // this is a bit complicated, but I will try to explain anyway.
    // first we make a rectangle and set its width to 100.
    var rectangle:Rectangle = new Rectangle(0,0,100,0);

    // then we need a varible to check if the handle is being dragged.
    var dragging:Boolean false;

    // the eventlistener for startdragging
    volume_mc.mySlider_mc.addEventListener(MouseEvent.MOUSE_DOWNstartDragging);
    function 
    startDragging(event:Event):void {

    // here we tell flash the margin on where it should be able to drag, (remember 100 pixels back and forth)
    volume_mc.mySlider_mc.startDrag(false,rectangle);
    dragging true;

    // This is very important, an eventlistener so we can change the volume, not only make it look good.
    volume_mc.mySlider_mc.addEventListener(Event.ENTER_FRAMEadjustVolume);
    }

    // well here is the adjust volume function, its not that complicated
    function adjustVolume(event:Event):void {

    // we make a variable to calculate the volume from the slider handle position and divide it by 100
    var myVol:Number volume_mc.mySlider_mc.100;
    // then we set it with the mySoundTransform
    var mySoundTransform:SoundTransform = new SoundTransform(myVol);
    if (
    mySoundChannel != null) {
    mySoundChannel.soundTransform mySoundTransform;
    }
    }

    // and of cause the stop draggin function, I dont feel the need to explain it.
    stage.addEventListener(MouseEvent.MOUSE_UPstopDragging);
    function 
    stopDragging(event:Event):void {
    if (
    dragging) {
    dragging false;
    volume_mc.mySlider_mc.stopDrag();
    }



    In particolare, però, non riesco a modificare due cose.
    1: non riesco a far partire la musica già in play. Mi spiego: quando apro l'.swf bisogna cliccare su play per far partire la musica: vorrei che la musica fosse già in play.
    2: non riesco a mettere la musica in loop.

    Se qualcuno mi aiuta gliene sarei molto grato! Grazie a tutti.

  2. #2
    Utente di HTML.it
    Registrato dal
    Feb 2008
    Messaggi
    21
    Chiedo scusa. Ho sbagliato sezione. Non mi ero accorto della sezione dedica all'AS. Sarebbe possibile spostarlo li?grazie e ancora scusa.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.