Home Tutorials Forums Articles Blogs Movies Library Employment Press

<< Prev 5 | Next 5

seek bar (with mp3 load)

_root.createEmptyMovieClip("seek",1)

seek.w=200			// seek bar width
seek.h=20			// seek bar height
seek.b=2			// seek bar border
seek.bgc="0x000000"		// seek bar background color
seek.fgc="0xffffff"		// seek bar foreground color

drawSquare=function(mc,w,h,l,t,c) {
        with(mc){
                beginFill(c,100)
                moveTo(l,t)
                lineTo(l+w,t)
                lineTo(l+w,t+h)
                lineTo(l,t+h)
                lineTo(l,t)
                endFill()
        }
        return mc
}

seek.jump=function() {
        x=seek.bg._xmouse
        if (x<seek.b) {p=0}
        else if (x>seek.w-seek.b) {p=100}
        else {p=(x-seek.b)/(seek.w-2*seek.b)}
        mp3.start(p*(mp3.duration/1000))
}

seek.init=function  () {
        seek.createEmptyMovieClip("bg",1)
        drawSquare(seek.bg,seek.w,seek.h,0,0,seek.bgc)
        seek.createEmptyMovieClip("fg",2)
        drawSquare(seek.fg,1,seek.h-2*seek.b,0,seek.b,seek.fgc)._x=seek.b
        seek.onPress=function  () {
                seek.jump()
                seek.onMouseMove=function () {
                        if (seek.bg.hitTest(_root._xmouse,_root._ymouse,false)){seek.jump()}
                }
        }
        seek.onRelease=seek.onReleaseOutside=function  () {
                delete seek.onMouseMove
        }
}

var mp3:Sound = new Sound();
mp3.onLoad = function(success:Boolean) {
        if (success) {
                seek.init()
                mp3.start();
                _root.onEnterFrame=function  () {
                        seek.fg._width=(seek.w-2*seek.b)*(mp3.position/mp3.duration)
                }
                mp3.onSoundComplete=function  () {
                        mp3.start(0)
                }
        }
};

mp3.loadSound("sound.mp3", true);

Posted by: ysle | website http://ysle.com
seek bar 2 (with mp3 preload)
_root.createEmptyMovieClip("seek",1)

seek.w=400		// seek bar width
seek.h=20		// seek bar height
seek.b=2		// seek bar border
seek.plc="0xff0000"	// seek bar preload color
seek.bgc="0x000000"	// seek bar background color
seek.fgc="0xffffff"	// seek bar foreground color

plw=seek.w-2*seek.b

MovieClip.prototype.drawSquare=function(w,h,l,t,c) {
        with(this){
                clear()
                beginFill(c,100)
                moveTo(l,t)
                lineTo(l+w,t)
                lineTo(l+w,t+h)
                lineTo(l,t+h)
                lineTo(l,t)
                endFill()
        }
        return this
}

seek.jump=function() {
        mp3.start((((seek.bg._xmouse-seek.b)/plw)*(mp3.duration/loaded))/1000)
}

seek.createEmptyMovieClip("bg",1).drawSquare(seek.w,seek.h,0,0,seek.bgc)
seek.createEmptyMovieClip("pl",2).drawSquare(1,seek.h-2*seek.b,0,seek.b,seek.plc)._x=seek.b
seek.createEmptyMovieClip("fg",3).drawSquare(1,seek.h-2*seek.b,0,seek.b,seek.fgc)._x=seek.b

mp3=new Sound()
mp3.loadSound("sound.mp3", true)
mp3.start(0)
seek.pl.onEnterFrame=function () {
        out=loaded=mp3.getBytesLoaded()/mp3.getBytesTotal()
        this._width=plw*loaded
        seek.fg._width=out2=(mp3.position/(mp3.duration/loaded))*plw
}
seek.pl.onPress=function  () {
        seek.jump()
        this.onMouseMove=function () {
                if (this.hitTest(_root._xmouse,_root._ymouse,false)){seek.jump()}
        }
}
seek.pl.onRelease=seek.pl.onReleaseOutside=function  () {
        delete this.onMouseMove
}

Posted by: ysle | website http://ysle.com
Simple Fader (In & Out)
//**********************************************************************
// ************************** "_root" SCRIPT****************************
//**********************************************************************
Volumen = "0";
TopeVolumen = "0";
MiSonido = new Sound();
MiSonido.attachSound("MiSonidoInLibrary");
MiSonido.setVolume(0);
MMiSonido.start(0, 1);

// ************* LOOP MANAGER ***************
MiSonido.onSoundComplete = function() {
        MiSonido.start(0, 1);
}
};

// ************ VOLUME MANAGER **************
_root.onEnterFrame = function() {
        if (Volumen<TopeVolumen) {
                ++Volumen;
        } else if (Volumen>TopeVolumen) {
                --Volumen;
        }
        MySound.setVolume(Volumen);
};
//**********************************************************************
// ************************ "Some Button" SCRIPT************************
//**********************************************************************
on (press) {
        if (TopeVolumen>10) {
                TopeVolumen = 0;
        } else if (TopeVolumen<1) {
                TopeVolumen = 100;
        }
}

Posted by: Isaac L.A. (Azz) | website http://www.none.azz
simple mp3 control with sound object(object object)function
//the first of the global variables needs to remain but the three following
//it were used for a seperate function not displayed here ang should be ommitted
//and replaced with locals within the function, although they work fine for this
//demo
//in order for flash to dynamically increment & decrement my sounds for me
//and still have reference to them w/o any further effort on my part I picked
//the mp3's I wanted (9 total) named them sound1.mp3, sound2.mp3,etc...
//imported all 9, and linked them to actionscript with they're new names

_global.gSoundNum = "1";
_global.gSoundMc = "";
_global.gSoundMcp = "";
_global.gSoundMpp = "";

//with the setSound() function I wanted my set of songs to play one after
//another in and repeat the entire loop untill stopped, but i also wanted
//the option of skipping to the next or previous song with the ability to cycle
//the entire playlist just pressing one button, which ever direction you happen
//to press without having to stop and go the other direction
//this brought up a problem
//you can't loop streams so I had to import all 9 sounds making a huge site
//and had to change the "mysound.loadSound()" to "attachSound" and added
//an onSoundComplete increment function for the loop
//there is probobly a thousand ways to do this better, but it works for me
//and it worked the first time which blew my mind
//please e-mail me and tell me how I can make it better
//with the gSoundNum as the place holder in the set sound function I gave myself
//the option of linking to a specific sound file if I wanted to in the future

setSound = function (gSoundNum) {
        stopAllSounds();
        gSoundMc = "sound";
        gSoundMc = gSoundMc+gSoundNum;
        gSsoundMcp = gSoundMc+"_mc";
        gSoundMpp = gSoundMc+".mp3";
        _root.createEmptyMovieClip(gSoundMc, 13);
        mySound = mySound+gSoundNum;
        mySound = new Sound(gSoundMc);
        mySound.attachSound(gSoundMpp);
        mySound.start();
        mySound.onSoundComplete = function() {
                gSoundNum++;
                _root.setSound();
        };
}
_root.allButtons_mc.play_btn.onRelease = function() {
        _root.setSound();
}
_root.allButtons_mc.stop_btn.onRelease = function() {
        stopAllSounds();
}

_root.allButtons_mc.next_btn.onRelease = function() {
        if (gSoundNum == 5) {
                gSoundNum = 9;
        } else {
                gSoundNum++;
        }
        _root.setSound();
};

_root.allButtons_mc.previous_btn.onRelease = function() {
        if (gSoundNum == 1) {
                gSoundNum = 9;
        } else {
                gSoundNum--;
        }
        _root.setSound();
};

Posted by: joe james | website http://www.imujan.com
Simple MP3 Player
/*---------For the main timeline---------*/
stop();
_root.isPlaying = false;
_root.fileName = "text.mp3"; //MP3 file to play
_root.sound = new Sound();
_root.sound.onSoundComplete = endSound;

function playSound(filename) {
        _root.sound.stop();
        trace(filename);
        _root.sound.loadSound(filename, true);
        _root.sound.start();
}

function endSound() {
        _root.isPlaying = false;
}

function toggleSong() {
        if(!_root.isPlaying) {
                _root.playSound(_root.fileName);
                _root.isPlaying = true;
        } else {
                stopAllSounds();
                _root.isPlaying = false;
        }
}

/*---------For button that plays song---------*/
on(press) {
        _root.toggleSong();
}

Posted by: Tony Myatt | website http://tony.myatt.com.au

<< Prev 5 | Next 5

Copyright 2000-2010 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.