0

オンラインで見つけた次のスクリプト(AS3)を使用して、フラッシュで音楽を再生しました。アクションスクリプトがわかりません。

//imports the necessary as events
import flash.events.Event
import flash.events.MouseEvent;

var isPlaying:Boolean = new Boolean();
var pausePosition:Number = new Number();

//Create an instance of the Sound class
var soundClip:Sound = new Sound();
//Create a new SoundChannel Object
var sndChannel:SoundChannel = new SoundChannel();

//Load sound using URLRequest
soundClip.load(new URLRequest("music.mp3"));
//Create an event listener that wll update once sound has finished loading
soundClip.addEventListener(Event.COMPLETE, onComplete, false, 0, true);

music_play.addEventListener(MouseEvent.MOUSE_DOWN, btnPressController, false, 0, true);
music_stop.addEventListener(MouseEvent.MOUSE_DOWN, btnPressStop, false, 0, true);

function onComplete(evt:Event):void {
    //Play loaded sound
    sndChannel = soundClip.play();
    isPlaying = true;
}

function btnPressController(evt:MouseEvent):void
{
    switch(isPlaying)
    {
        case true:
            music_play.gotoAndStop(2);
            pausePosition = sndChannel.position; 
            sndChannel.stop();
            isPlaying = false;
        break;
        case false:
            music_play.gotoAndStop(1);
            sndChannel = soundClip.play(pausePosition);
            isPlaying = true;
        break;
    }
}

function btnPressStop(evt:MouseEvent):void
{
    pausePosition = 0;
    sndChannel.stop();
    music_play.gotoAndStop(2);
    isPlaying = false;
}

上記のスクリプトでわかるように、music_playmusic_stop再生ボタンと停止ボタンのインスタンス名です。.mp3ファイルをロードすると、音楽が再生されるはずですが、音楽はFlashから表示した場合にのみ再生されます。しかし、ローカルまたはオンライン(http://ulfhc.com.au/)で表示すると、音楽が再生されません。.swfまたは.mp3ファイルの場所が原因ではないと確信しています。

これを手伝ってくれませんか。

どうもありがとうございます。

編集:

では、新しいコードはこれでしょうか?

import flash.events.Event
import flash.events.MouseEvent;

var isPlaying:Boolean = new Boolean();
var pausePosition:Number = new Number();

var soundClip:Sound;

function init() {
    soundClip = new Sound();
    soundClip.load(new URLRequest("music.mp3"));
    soundClip.addEventListener(Event.COMPLETE, soundLoaded);
    soundClip.addEventListener(ProgressEvent.PROGRESS, soundLoading);
    music_play.addEventListener(MouseEvent.MOUSE_DOWN, btnPressController, false, 0, true);
    music_stop.addEventListener(MouseEvent.MOUSE_DOWN, btnPressStop, false, 0, true);
}
init();

function onComplete(evt:Event):void {
    sndChannel = soundClip.play();
    isPlaying = true;
}

function soundLoaded(e:Event) {
    soundClip.play();
}

function soundLoading(e:ProgressEvent) {
    // preloader information goes here
}

function btnPressController(evt:MouseEvent):void
{
    switch(isPlaying)
    {
        case true:
            music_play.gotoAndStop(2);
            pausePosition = sndChannel.position; 
            sndChannel.stop();
            isPlaying = false;
        break;
        case false:
            music_play.gotoAndStop(1);
            sndChannel = soundClip.play(pausePosition);
            isPlaying = true;
        break;
    }
}

function btnPressStop(evt:MouseEvent):void
{
    pausePosition = 0;
    sndChannel.stop();
    music_play.gotoAndStop(2);
    isPlaying = false;
}
4

1 に答える 1

0

ローカル/ネットワークアクセスごとに、Flash公開設定の[ローカル再生セキュリティ]が[ローカルファイルのみにアクセス]ではなく[ネットワークのみにアクセス]に設定されていることを確認します

また、パスがホストされているデプロイメントの環境と一致していることを確認してください。URLとして「music.mp3」を参照する場合、「music.mp3」は公開されたSWFと同じ場所に存在する必要があります。

ストリーミングの代わりにmp3をプリロードするごとに、サウンドEvent.COMPLETEを呼び出す前にリッスンしplay()ます。

var soundClip:Sound;

function init() {
    soundClip = new Sound();
    soundClip.load(new URLRequest("<path to sound file>"));
    soundClip.addEventListener(Event.COMPLETE, soundLoaded);
    soundClip.addEventListener(ProgressEvent.PROGRESS, soundLoading);
}
init();

function soundLoaded(e:Event) {
    soundClip.play();
}

function soundLoading(e:ProgressEvent) {
    // preloader information goes here
}

mp3をストリーミングする必要がない場合は、ライブラリに埋め込むこともできます。

サウンドクリップ

サウンドを再生できる場所:

var soundClip:Sound = new SoundClip(); 
soundClip.play();
于 2012-07-20T19:28:00.630 に答える