Skip navigation
Currently Being Moderated

Controlling the sound volume of my swf

May 15, 2013 2:47 PM

I am trying to reduce the sound volume of my swf in general. I implemented the code below, but I get this error message: Line 30 1151: A conflict exists with definition in namespace internal.

 

Thanks for your help

Charine

++++++++++++++++++++++++++++

Here is my code:

package

{

   import flash.display.MovieClip;

    import flash.utils.Timer;

    import flash.events.TimerEvent;

    import flash.events.MouseEvent;

    import flash.media.Sound;

   import flash.events.Event;

    import flash.media.SoundChannel;

    import flash.media.SoundMixer;

    import flash.media.SoundTransform;

 

 

    public class BugGoopFSGame extends MovieClip

    {

       public var mybackground:BackGround;

//        public var LetterArray:LetterArray = new LetterArray(stage);

        public var lettera:A;

        public var cinders:Cinders;

        public var gameTimer:Timer;

        public var spidy:Spidy;

        public var myplaybtn:Play;

        public var timerback:TimerBack;

        public var timermiddle:TimerMiddle;

        public var timerfront:TimerFront;

        public var settings_btn:Settings_btn;

        public var sound1:Sound1;

        public var channel:SoundChannel = (new Sound1()).play(0, int.MAX_VALUE);

       

        public var channel:SoundTransform = (new Sound1()).volume(0.5,1.0); //This is where the problem is - Line 30 1151: A conflict exists with definition in namespace internal.

 

                       

       

        public function BugGoopFSGame()

        {

           

            sound1 =  new Sound1();

           

        //rest is not relevant to this

 
Replies
  • Currently Being Moderated
    May 15, 2013 3:57 PM   in reply to Charine -FB buggoop

    You declared two different variables with the same name "channel". Change the name of one of them.

     
    |
    Mark as:
  • Currently Being Moderated
    May 15, 2013 6:11 PM   in reply to Charine -FB buggoop

    This is probably what you should be doing. Define the sound channel and the sound transform objects. Then tell the sound to play through the sound channel, then set the volume for the sound channel through the sound transform.

     

    public var channel1:SoundChannel;

    public var channel2:SoundTransform = channel1.soundTransform;

     

    Sound1.play(0, int.MAX_VALUE);

    channel2.volume = .5;

    channel1.soundTransform = channel2;

     

    See how that works.

     
    |
    Mark as:
  • Currently Being Moderated
    May 17, 2013 12:13 PM   in reply to Charine -FB buggoop

    Can I see the whole Class? You've either left out something or put something in the wrong place.

     
    |
    Mark as:
  • Currently Being Moderated
    May 18, 2013 2:09 PM   in reply to Charine -FB buggoop

    Try this version that I put together. I attached the sound playing to the onClick function at the bottom. This may not be the correct place, you can move the code to any function that you like. The sound will not play from the variable declaration section of the class, it really needs to be in a function.

     

    package  {

     

                import flash.display.*;

        import flash.utils.Timer;

        import flash.events.*;

        import flash.events.MouseEvent;

        import flash.media.Sound;

        import flash.events.Event;

        import flash.media.SoundChannel;

        import flash.media.SoundMixer;

        import flash.media.SoundTransform;

        import flash.text.*;

        import flash.net.URLRequest;

     

        public class BugGoopFSGame extends MovieClip

        {

            public var mybackground:BackGround;

            public var letterArray:LetterArray = new LetterArray(stage);

            public var lettera:A;

            public var cinders:Cinders;

            public var gameTimer:Timer;

            public var spidy:Spidy;

            public var myplaybtn:Play;

            public var timerback:TimerBack;

            public var timermiddle:TimerMiddle;

            public var timerfront:TimerFront;

            public var settings_btn:Settings_btn;

            public var sound1:Sound;

            public var channel1:SoundChannel = new SoundChannel();

            public var channel2:SoundTransform = channel1.soundTransform;

          

            public function BugGoopFSGame()

            {

                                  // this assumes that you have a sound file in a movie Library

                                  // with a class name of "Sound1"

                sound1 =  new DeltaFog();

              

                lettera = new A ();

                addChild(lettera);

     

     

                                  mybackground = new BackGround ();

                addChild(mybackground);

     

                cinders = new Cinders();

                addChild(cinders);

     

                spidy = new Spidy();

                addChild(spidy);

     

                myplaybtn = new Play();

                addChild(myplaybtn);

     

                timerback = new TimerBack();

                addChild(timerback);

     

                timermiddle = new TimerMiddle();

                addChild(timermiddle);

     

                timerfront = new TimerFront();

                addChild(timerfront);

              

                settings_btn = new Settings_btn();

                addChild(settings_btn);

     

                gameTimer = new Timer(31,5120);

     

                //Add event listener for start button

                myplaybtn.addEventListener(MouseEvent.CLICK, startTimer);

                //Add event listener for timer;

                gameTimer.addEventListener(TimerEvent.TIMER, tickTock);

                gameTimer.addEventListener(TimerEvent.TIMER_COMPLETE, timerFinished);

                gameTimer.addEventListener(TimerEvent.TIMER, fadeIn);

                gameTimer.addEventListener(TimerEvent.TIMER, moveA);

                gameTimer.addEventListener(TimerEvent.TIMER, scaleLifeBar);

     

                //Add event listener for when lettera is clicked

                lettera.addEventListener(MouseEvent.MOUSE_DOWN, onClick);

     

     

            }

     

            //Start timer function

            public function startTimer(timerEvent:MouseEvent):void

            {

                gameTimer.start();

                trace("Timer started");

                myplaybtn.visible = false;

            }

          

            public function tickTock(timerEvent:TimerEvent):void

            {

                trace("Tick");

            }

     

            public function timerFinished(timerEvent:TimerEvent):void

            {

                trace("Timer is finished");

            }

     

            public function scaleLifeBar(timerEvent:TimerEvent):void

            {

                timermiddle.scaleLifeBar();

            }

     

            public function fadeIn(timerEvent:TimerEvent):void

            {

                lettera.fadeIn();

            }

     

            public function moveA(timerEvent:TimerEvent):void

            {

                lettera.moveA();

            }

     

            public function onClick(event:MouseEvent):void

            {

                trace("The letter a was clicked");

                                  // this line tells the sound to play, it can also

                                  // be "sound1.play(0,int.MAX_VALUE);" if you don't need

                                  // the volume

                                  channel1 = sound1.play(0, int.MAX_VALUE);

                                  // set a value for the volume to be used

                               channel2.volume = .5;

                                  // connect the volume to the sound channel

                      channel1.soundTransform = channel2;

            }

        }

    }

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points