Senin, Februari 01, 2010

Membuat Music Sound Control

1. Buat 3 buah layer kemudian rename menjadi action,tombol dan box.

2. Import 3 buah file musik kedalam library, kemudian linkage file satu per satu dan rename menjadi musik1, musik2, dan musik3.

3. Pilih window-command library-button, kemudian drag 3 buah tombol ke dalam library.

4. Sediakan tombol volume dan balance pada library

5. Pilih layer box, kemudian buat sebuah gambar untuk meletakkan tombol-tombol.

6. Pilih layer action,pada frame pertama masukkan action:
mySound=new Sound();

7. Pada layer tombol, buat tombol untuk play dan pause.
• Klik kanan pada tombol play, kemudian masukkan action:
on (release) {
mySound.start();}
• Klik kanan pada tombol stop, kemudian masukkan action:
on (release) {
mySound.stop();}

8. Drag tombol-tombol dari library dan berikan label pada masing-masingnya dengan nama musik1,musik2, dan musik3.
• Klik kanan pada tombol musik1, dan masukkan action:
on (release) { mySound.attachSound("musik1");
mySound.stop();
mySound.start(0,1);
}
• Klik kanan pada tombol musik2, dan masukkan action:
on (release) { mySound.attachSound("musik2");
mySound.stop();
mySound.start(0,1);
}
• Klik kanan pada tombol musik3, dan masukkan action:
on (release) { mySound.attachSound("musik3");
mySound.stop();
mySound.start(0,1);
}

9. Drag tombol volume dan balance ke layer.
• Double klik tombol volume, kemudian pada frame1 layer4 berikan action:
top = vol._y;
left = vol._x;
right = vol._x;
bottom = vol._y+100;
level = 100;
//
vol.onPress = function() {
startDrag("vol", false, left, top, right, bottom);
dragging = true;
};
vol.onRelease = function() {
stopDrag();
dragging = false;
};
vol.onReleaseOutside = function() {
dragging = false;
};
//
this.onEnterFrame = function() {
if (dragging) {
level = 100-(vol._y-top);
} else {
if (level>100) {
level = 100;
} else if (level<0) {
level = 0;
} else {
vol._y = -level+100+top;
}
}

_root.mySound.setVolume(level);
};
• Double klik tombol balance,kemudian pada frame1 layer4 berikan action:
increment = 4;
level = 0;
//
panKnob.onPress = function() {
if (Key.isDown(Key.getCode(18))) {
autoPan = true;
} else {
autoPan = false;
start = _root._xmouse;
newStart = panKnob._rotation;
dragging = true;
}
};
panKnob.onRelease = function() {
dragging = false;
};
panKnob.onReleaseOutside = function() {
dragging = false;
};
//
this.onEnterFrame = function() {
if (dragging) {
pivot = (_root._xmouse-start)*2+newStart;
panKnob._rotation = pivot;
if (pivot<-135) {
panKnob._rotation = -135;
}
if (pivot>135) {
panKnob._rotation = 135;
}
level = Math.round(panKnob._rotation/1.35);
} else {
if (autoPan) {
textInput.value.selectable = false;
level += increment;
if (level>99 || level<-99) {
increment *= -1;
}
} else {
textInput.value.selectable = true;
}
if (level>100) {
level = 100;
} else if (level<-100) {
level = -100;
} else if (level<=100 && level>=-100) {
panKnob._rotation = level*1.35;
}
}
_root.mySound.setPan(level);
};
• Test Movie (ctrl + enter)



Keterangan fungsi dari masing-masing script:

1. mySound = new Sound(); fungsinya : untuk memutar sound yang telah kita masukkan.

2. on (release) { mySound.attachSound("musik1");

mySound.stop();

mySound.start(0,1);

}

Scrib diatas digunakan pada tombol pilihan musik,contohnya pada musik 1.

(0,1) berarti musik hanya diputar 1 kali saja. Jika dibuat 10 maka akan diputar sebanyak 10.

3. on (release) {

mySound.stop();}

scrib diatas dibuat pada tombol stop. Tujuannya untuk menstop musik.

4. on (release) {

mySound.start();}

scrib ini dibuat pada tombol play. Digunakan untuk memainkan musik.

5. _root.mySound.setVolume(level);

Scrib diatas dibuat pada tombol volume yang digunakan untuk mengatur volume musik.

6. _root.mySound.setPan(level);

Srib diatas dibuat pada tombol balance.digunakan untuk menagatur balance musik.