swapChildren - referencing the items..?

Ok - I know I’ve appeared here today with a few questions - my last of the day I promise!

My doc class (Main.as) calls and builds a few graphics (doBuild.as) and some text (mainText.as).

I’m trying to target the dynamic text with a listener (in the MainText.as) and swap the graphics when clicked - trouble being that I can’t seem to reference them back at all (i.e stage.swapChildren(doBuild.Navigation,doBuild.Navigation2);).
Can anyone shed light on this?

Main.as

 
package {
 import flash.display.Sprite;
 import flash.display.MovieClip; 
 import flash.display.*
 public class Main extends Sprite {
  public function Main():void {
   var doBuild = new DoBuild(this);
   addChild(doBuild);
 
   var mainText = new MainText(this);
   addChild(mainText);
 
  }
 }
}

MainText.as

 
package {
 import flash.display.MovieClip; 
 import flash.text.*;
 import flash.events.*; 
 public class MainText extends MovieClip {
 
 public function MainText(stage:Main) { 
  var css:StyleSheet = new StyleSheet();
  var body:Object = new Object();
  body.fontFamily = "Arial";
  body.textIndent = 0;
  css.setStyle("body", body);
   var txtFld:TextField = new TextField();
   txtFld.x =830;
   txtFld.y =10;   
   txtFld.width = 100;
   txtFld.multiline = true;
   txtFld.wordWrap = true;
   txtFld.selectable = false;   
   txtFld.embedFonts = true;
   txtFld.autoSize = TextFieldAutoSize.LEFT;
   txtFld.styleSheet = css;
   txtFld.htmlText = "<body>";
   txtFld.htmlText += "<span class='heading'>Text</span>";
   txtFld.htmlText += "</body>";
   addChild(txtFld);
   txtFld.addEventListener(MouseEvent.CLICK, clickHandler);
    function clickHandler(event:Event):void
    {
     stage.swapChildren(doBuild.Navigation,doBuild.Navigation2);
 
    }   
}
}
}

doBuild.as

 
package {
 import flash.display.Sprite; 
 public class DoBuild extends Sprite {
 public function DoBuild(stage:Main) {
   var Navigation2:Sprite=new rightPanel2();
   addChild(Navigation2);
   trace("NAV2 = " + getChildIndex(Navigation2));
   Navigation2.x=832;
   Navigation2.y=2.4; 
   var Navigation:Sprite=new rightPanel();
   addChild(Navigation);
   trace("NAV = " + getChildIndex(Navigation));
   Navigation.x=832;
   Navigation.y=2.4;   
  } 
 }
}

Have it dispatch an event that the Main is listening for instead.

that way you keep any reference to it’s parent out of the class…

Thanks once again Sekasi, I’d figured it was a simple referencing error I was committing but this opens up a whole new bag of worms (and bugs) to me.

I’ll give it a bash and see where I get.

Really do appreciate your feedback here - many thanks once again!