0

私は Actionscript 3 が初めてで、Flash CS6 を使用しています。

-countrymeadow という名前の 20 分間の mp3 を再生/一時停止しようとしています

-countrymeadow.mp3 は、ライブラリの actionscript (countrymeadow) のエクスポート用にリンクされています。

  • playpause mc ボタンは、ボタン内の 1 フレーム目 (再生) と 10 フレーム目 (一時停止) で停止します。

  • AS3 はそれ以下ですが、テスト時に mc playpause ボタンが常に「再生」と「一時停止」を切り替え、サウンドが再生されないため、機能していません。

どんな助けでも大歓迎です、そして前もって多くの感謝をします。

//set appearance of button, mode to true
playpause_mc.gotoAndStop("play");
playpause_mc.buttonMode = true;

//sound is stopped after loaded
var isPaused:Boolean = true;

//saves current position of sound
var currPos:int = 0.00;

var theSound:countrymeadow = new countrymeadow();
snd.play(); 

var soundCnl:SoundChannel = new SoundChannel();

//Listener updates after sound loads, and stops           soundtheSound.addEventListener(Event.COMPLETE, onComplete, false, 0, true);
function onComplete(evt:Event):void {
    //Stop loaded sound
    soundCnl.stop();
}


// movie clip button control
playpause_mc.addEventListener(MouseEvent.CLICK, clickHandler);
function clickHandler(event:MouseEvent):void {

    if(isPaused){
        //change state to playing, and play sound from position
        isPaused = false;
        soundCnl = theSound.play(currPos); 

        //reverse the appearance of the button
        playpause_mc.gotoAndStop("pause")

        //if sound completes while playing, run function
        soundCnl.addEventListener(Event.SOUND_COMPLETE, soundCompleteHandler);

    }else{
        //it's playing, so save position and pause sound
        currPos = soundCnl.position;
        isPaused = true;
        soundCnl.stop();

        //change the appearance of the buttons
        playpause_mc.gotoAndStop("play")
    }
}
4

1 に答える 1

0

SoundChannelpositionNumber変数です。それは0から1の範囲ですが、int変数に設定されています。int浮動小数点型ではありません。型として明示的に宣言したためですint。浮動小数点初期化になった場合でも、int型に変換します。

ここに画像の説明を入力

これに従う必要があります。そしてあなたのclickHandler関数はいくつか修正されました。

var currPos:Number = 0.0;

soundCnl.addEventListener(Event.SOUND_COMPLETE, soundCompleteHandler);
function clickHandler(event:MouseEvent):void {

    if(isPaused){
        //change state to playing, and play sound from position
        isPaused = false;
        soundCnl.play(currPos); 

        //reverse the appearance of the button
        playpause_mc.gotoAndStop("pause")

    }else{
        //it's playing, so save position and pause sound
        currPos = soundCnl.position;
        isPaused = true;
        soundCnl.stop();

        //change the appearance of the buttons
        playpause_mc.gotoAndStop("play")
    }
}

テストコード:

var n:int = 0.0;

n = 0.5;

trace("n: " + n); //you may expected 0.5, but return 0.
于 2012-09-05T03:07:48.037 に答える