# Question about if/else if

**URL:** <https://forum.kirupa.com/t/question-about-if-else-if/324041>\
**Category:** flash\
**Created:** [July 29, 2011, 3:16pm UTC](https://forum.kirupa.com/t/question-about-if-else-if/324041 "2011-07-29T15:16:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![siriso](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@siriso](https://forum.kirupa.com/u/siriso)\
**Post date:** [July 29, 2011, 3:16pm UTC](https://forum.kirupa.com/t/question-about-if-else-if/324041/1 "2011-07-29T15:16:15Z")

</div>

I’m making a navigation bar which contains 4 buttons, each button will load external swf file when clicked.  
I want that every time one swf file is added to stage, it’ll replace the previous one.  
Therefore I created a variable j in order to prevent any stack of the swf files.  
It doesn’t work as only the first swf file was able to be added to and removed from stage.

Any suggestion??

```auto

var j:int = 0;
var _SWFLoader:SWFLoader;
var swfCont:Sprite = new Sprite();
addChild(swfCont);

button1.name = "button1";
button2.name = "button2";
button3.name = "button3";
button4.name = "button4";

button1.addEventListener(MouseEvent.CLICK, gotClicked);
button2.addEventListener(MouseEvent.CLICK, gotClicked);
button3.addEventListener(MouseEvent.CLICK, gotClicked);
button4.addEventListener(MouseEvent.CLICK, gotClicked);

function gotCLicked(e:MouseEvent):void
{
    j += 1;
        
    if (j == 1)
    {
        if (e.target.name == "button1")
        {
            _SWFLoader = new SWFLoader("AAA.swf");
            _SWFLoader.load();
            swfCont.addChild(_SWFLoader.content);
        }
        
        if (e.target.name == "button2")
        {
           _SWFLoader = new SWFLoader("BBB.swf");
           _SWFLoader.load();
           swfCont.addChild(_SWFLoader.content);
        }
        
        if (e.target.name == "button3")
        {
           _SWFLoader = new SWFLoader("CCC.swf");
           _SWFLoader.load();
           swfCont.addChild(_SWFLoader.content);
        }
        
        if (e.target.name == "button4")
        {
            _SWFLoader = new SWFLoader("DDD.swf");
            _SWFLoader.load();
            swfCont.addChild(_SWFLoader.content);
        }
    }
    else if (j > 1)
    {
        swfCont.removeChild(_SWFLoader.content);
        j = 1;
    }
}

```
