A Flash Developer Resource Site

Results 1 to 14 of 14

Thread: another "if" statement inside an "if" statement???

Threaded View

  1. #1
    Junior Member
    Join Date
    Sep 2010
    Posts
    15

    Unhappy another "if" statement inside an "if" statement???

    Hi Everyone,

    I have a scenario where I need to write an if statement inside an if-else statement. But no matter how I write it it keeps giving me a syntax error...
    The syntax error is "1083: syntax error: else is unexpected"

    Actionscript Code:
    var bgMusicURL:URLRequest = new URLRequest("background music.mp3");
    var bgVoiceURL:URLRequest = new URLRequest("bracey Voice.mp3");
    var bgVoice:Sound = new Sound(bgVoiceURL);
    var bgMusic:Sound = new Sound(bgMusicURL);
    var channel1:SoundChannel = new SoundChannel();
    var channel2:SoundChannel = new SoundChannel();
    var musicPosition:Number;
    var voicePosition:Number;
    var musicDimmer:SoundTransform = new SoundTransform(.2, 0);
    var volumeControle:Number = SoundMixer.soundTransform.volume;
    var buttonsArray:Array = new Array(playMusic_btn, playVoice_btn, pause_btn, replay_btn, stop_btn);
    var volumeButtonsArray:Array = new Array(volUp_btn, volDown_btn);

    //Functions
    function buttonsFunction(evt:Event):void {
        if (evt.target.name == playMusic_btn.name) {
            channel1.stop();
            channel1 = bgMusic.play();
        } else if (evt.target.name == playVoice_btn.name) {
            channel2.stop();
            channel1.soundTransform = musicDimmer;
            channel2 = bgVoice.play();
        } else if (evt.target.name == pause_btn.name) {
            musicPosition = channel1.position;
            voicePosition = channel2.position;
            channel1.stop();
            channel2.stop();
        } else if (evt.target.name == replay_btn.name) {
            channel1.stop();
            channel2.stop();
            channel1 = bgMusic.play(musicPosition);
            channel1.soundTransform = musicDimmer;
            channel2 = bgVoice.play(voicePosition);
        } else if (evt.target.name == stop_btn.name) {
            channel1.stop();
            channel2.stop();
        }
    }

    function volumeFunction(evt:Event):void {
        if (evt.target.name == volUp_btn.name) {
            volumeControle += .1;
            if (volumeControle > 1) {        [COLOR="Red"]<<----------this is the if that is giving me trouble [/COLOR]
                volumeControle = 1;}
           
        }
        SoundMixer.soundTransform = new SoundTransform(volumeControle, 0);
        trace("volume up: " + volumeControle);
        //end volume up function
        else if (evt.target.name == volDown_btn.name) {
            volumeControle -= .1;
            if (volumeControle < 0) {                           [COLOR="Red"]<<-----------same thing[/COLOR]
                volumeControle = 0;}
           
        }
        SoundMixer.soundTransform = new SoundTransform(volumeControle, 0);
        trace("volume down: " + volumeControle);
            //end volume down function
    }


    //Listeners
    for (var i:Number = 0; i < buttonsArray.length; i++) {
        buttonsArray[i].addEventListener(MouseEvent.CLICK, buttonsFunction);
    }
    for (var ii:Number = 0; ii < volumeButtonsArray.length; ii++) {
        volumeButtonsArray[ii].addEventListener(MouseEvent.CLICK, volumeFunction);
    }


    No matter how or where I place the braces, it keeps giving me errors. As you can see I am new to AS and any help with some brief explanation would greatly help me out.

    Thank you very much in advance
    Last edited by aeson; 09-22-2010 at 06:46 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center