انجمن‌های فارس وب

نسخه کامل: ایجاد دکمه های ON و OFF و کم و زیاد کردن صدا در فلش
شما در حال بازدید از بایگانی ارسال های انجمن هستید این نسخه کامل نیست : برای مشاهده نسخه کامل اینجا کلیک کنید
در این آموزش سعی شده است طریقه قرار دادن دکمه ی ON و OFF برای صدا و لغزاننده صدا (برای کم و زیاد شدن صدا) را به طور مختصری بررسی نماییم.

البته قبلا آموزشی در مورد [ جهت مشاهده لينك عضو شويد ! ] در همین انجمن ها بوده که می تونید از اون استفاده کنید.

مرحله اول : قرار دادن دکمه و لغزاننده در صفحه :
- 4 لایه ایجاد می کنیم و نام آن ها را به ترتیب : buttons, slider , action , background می گذاریم.
- دکمه را به عنوان دکمه on/off در صفحه قرار می دهیم و نام آن را در پنل Properties نام آن را playButton می گذاریم.
- یک دکمه هم برای slider هم به لایه buttons اضافه می کنیم . و نام آن را mySlider می گذاریم.
- نمونه مورد نظر برای اسلایدر را در لایه ی slider می آوریم آن را به Movie clip تبدیل نمایید و نام آن را mySliderBar بگذارید.

شکل پیشنهادی من به صورت زیر است :



در لایه Background پس زمینه مورد نظر خود را قرار دهید.



مرحله دوم : وارد کردن فایل صوتی

- از طریق منوی File/Import فایل صوتی خود را وارد نمایید.
- در Library بر روی فایل صوتی کایک راست نمایید و گزینه Linkage را انتخاب نماییدو در کادر محاوره ای Linkage Properties گزینه Export for ActionScript را انتخاب نمایید.



مرجله آخر : افزودن Action Script

در فریم اول از لایه action کد زیر را قرار دهید:


//Create an instance of the Sound object called "thisSound"
//and use the method "attachSound" to attach the sound from
//the library. Remember to link the sound in the library to
//export to an action script. (Right click on the
//symbol and choose "Linkage").
thisSound = new Sound;
thisSound.attachSound("mySound");
//Initialize the soundOn variable to false.
soundOn=false;



در این کد شما یک شی از نوع صدایتان ایحاد می کنید و مقدار متغییری به نام SoundOn را که برای تنظیمات وضعیت فایل صوتی از آن استفاده می کنیم را مقدار دهی می کنیم.

و سپس در فریم دوم از لایه Action کد زیر را می نویسیم :

//Stop the movie in the main timeline and wait for a
//button to be pushed or slided.
stop();
//playButton is the instance of the on/off button and
//on its release, if the sound is off, then it starts the
//sound playing, and sets soundOn to true. When the sound
//is complete, it begins again. thisSound is the instance of
//the sound object that was created in the action script in
//frame one.
playButton.onRelease = function() {
    if (soundOn==false) {
        thisSound.start();
        soundOn=true;
        song.onSoundComplete = function() {
            thisSound.start();
        }
//if the sound is on, while the button is pushed, then
//the sound stops, and soundOn is set to false.
    } else {
        thisSound.stop();
        soundOn=false;
    }
    
}



به وسیله این کد می توانیم صدا را روشن یا خاموش نماییم و تنظیم کنیم اگر به انتهای فایل صوتی رسید دوباره از اول آن را احرا نماید.
(توضیحات در خود کد هست اگر مشکلی بود مطرح نمایید.)

بر روی دکمه ی Slider کد زیر را بنویسید :

//This button is both a movie clip and a button, because it
//needs to respond as a button and it also needs to slide.
//To do this, you need to have it as a button in the symbol
// library, then assign it as a movie clip instance in the
//properties box.
onClipEvent(load){
//myY is the position of the slider button
//the button must be positioned at the bottom
//of the slider to start
    myY=_y;
    //the top of the slider bar is top
    top=_y-_root.mySliderBar._height;
    //the bottom of the slider bar is bottom, and it
    //is set by the position of the button, which must
    //be placed at the bottom.
    bottom= _y;
    //right and left are the _x position of the button
    //(the middle of the button)
    right=_x;
    left=_x;
    //set the volume to off. thisSound is created in the
    //action script in frame one, and needs to be targeted
    //by using the word "_root" in front of it.
    _root.thisSound.setVolume(0);
}

//The following lines allow the button/movie clip to be
//dragged, but only up and down and only for the
//height of the slider. Left and right are set to the
//same value, so it cannot go left or right, only up and
//down.
on(press){
    startDrag("",false,left,top,right,bottom);
}
on(release){
    stopDrag();
    //the volume is a number between zero and 100 and
    //represents the difference between the bottom of
    //the slider and the current position of the button
    //times the ratio of the full volume (100) to the
    //height of the slider bar. This gives a value of
    //100 when the slider button is at the top of the
    //slider bar, and adjusts the volume correctly for
    //every position in between the top and the bottom.
    _root.thisSound.setVolume((myY-_y)*100/_root.mySliderBar._height);
    }


در این کد هم تنظیمات حرکت خط بالای Slider رو مشخص می کنیم و هم صدا را تغییر می دهیم.


در سابر لایه ها بر روی فریم 2 کلیک کنید و دکمه ی F5 را بزنید .


حال فایل شما آماده است و می توانید آن را اجرا نمایید.

امیدوارم برایتان مفید باشد.

مرجع : 50fast Macromedia Flash MX Techniques

سلام
آموزشتون خوب بود
ولی این خط برنامه های اضافی چیه نوشتی ؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟ ؟

باتوجه به بند 5 قوانین کلی انجمنهای فارس وب ویرایش شد.
مرجع آدرس ها