Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

looping sound problem

Guest
Feb 15, 2013 Feb 15, 2013

i have this code

when i run it ; it plays only one time

its background music and i need to play it ina loop

what i need to add to my code?

thank you

my code:

import flash.media.SoundChannel;

import flash.events.MouseEvent;

import flash.events.Event;

var isPlaying:Boolean = true;

var lastposition:Number = 0;

var mysound:mew = new mew();

var soundchannel:SoundChannel = new SoundChannel();//So now that we can play the sound, how do we stop it? You can NOT stop the sound using the Sound class (e.g. mysound.stop(); will not work). Another class is used for that - the SoundChannel class - which has a stop() method that will let you stop a sound's playback.

soundchannel = mysound.play(0,0);// playing sound in the channel

soundchannel.addEventListener(Event.SOUND_COMPLETE, onPlaybackComplete1);

        function onPlaybackComplete1(event:Event):void

        {

           

            lastposition = 0;

            soundchannel.stop();

            btn.btn_pause.visible = false;

            trace("finished");

            isPlaying=false;

           

        }

               

btn.addEventListener(MouseEvent.CLICK, playsound);

function playsound(event:MouseEvent):void

{

    if (! isPlaying)

    {

        soundchannel = mysound.play(lastposition,0);

        btn.btn_pause.visible = true;

        isPlaying = true;

        soundchannel.addEventListener(Event.SOUND_COMPLETE, onPlaybackComplete1);

                

    }

    else

    {

        lastposition = soundchannel.position;

        soundchannel.stop();

        btn.btn_pause.visible = false;

        /*trace(lastposition.toFixed(0), mysound.length.toFixed(0));*/

        isPlaying = false;

    }

soundchannel.addEventListener(Event.SOUND_COMPLETE, onPlaybackComplete);

        function onPlaybackComplete(event:Event):void

        {

           

            lastposition = 0;

            soundchannel.stop();

            btn.btn_pause.visible = false;

            trace("finished");

            isPlaying=false;

            soundchannel.addEventListener(Event.SOUND_COMPLETE, onPlaybackComplete);

           

           

        }

}

TOPICS
ActionScript
617
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Engaged , Feb 15, 2013 Feb 15, 2013

No sorry for the confusion I was pasting the API reference.

You just need to change this line in your code:

soundchannel = mysound.play(0, 0);// playing sound in the channel

to this:

soundchannel = mysound.play(0, int.MAX_VALUE);// playing sound in the channel

or anywhere where you call play() just pass int.MAX_VALUE for the second arg

Translate
Engaged ,
Feb 15, 2013 Feb 15, 2013

public function play(startTime:Number = 0, loops:int = 0, sndTransform:flash.media:SoundTransform = null):SoundChannel

When you call play - just passs it a really big number for the loop count

soundchannel = mysound.play(0, int.MAX_VALUE);// playing sound in the channel

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 15, 2013 Feb 15, 2013

Thank you

I dont have pakage so i cant add  public function

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 15, 2013 Feb 15, 2013

No sorry for the confusion I was pasting the API reference.

You just need to change this line in your code:

soundchannel = mysound.play(0, 0);// playing sound in the channel

to this:

soundchannel = mysound.play(0, int.MAX_VALUE);// playing sound in the channel

or anywhere where you call play() just pass int.MAX_VALUE for the second arg

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 15, 2013 Feb 15, 2013
LATEST

Thank you very very much

it's ok now

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines