hello i have started learning action script and ive been trying to create a dynamic nav bar.
the xml i have is

<home>

<navLinks>
<links>DESIGNER IN FOCUS</links>
<links>EMERGING TALENT</links>
<links>FASHION MENTOR</links>
<links>E-BOUTIQUE</links>
<links>FASHION JOBS</links>
</navLinks>

and i have found that

mainNavCont_mc.link01.linkTxt.text = "text in here";

works to replace one dynamic text (link01) on my stage, but i need to make it loop through and replace each of my links with xml

this is what i have so far

var fashionDataXML:XML;
var xmlLoader = new URLLoader;

trace("this runs");

xmlLoader.load(new URLRequest("fashionData.xml"));
xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);

function xmlLoaded(evt:Event):void{
	if ((evt.target as URLLoader) != null){
		fashionDataXML = new XML(xmlLoader.data);
		fashionDataXML.ignoreWhitespace = true;
		}//if
		createMenu();
	}//function xmlLoaded
function createMenu ():void {
	var i:uint = 0;
	trace("creatMenu");
	var links = fashionDataXML.home.navLinks.links;
	trace(links.length());
	trace("length traced");

	for ( var q=0;q<links.length();q++ ) {
		
		}

this all works so far -
as i understand the xml data is placed as text into fashionDataXML and the createMenu function has <links> tag targeted in my XML.
the q in the last for loop hits all 5 links as 0 1 2 3 4.

So im now stuck trying to think of what to do next to get each dynamic text from the xml placed into each link - link01 link02 link03 link04 and link05

i hope i have explained things well. thank you

Member Avatar for rajarajan2017

Hi,

var fashionDataXML:XML;
var xmlLoader = new URLLoader;
xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);
xmlLoader.load(new URLRequest("Data.xml"));

function xmlLoaded(evt:Event):void{
	if ((evt.target as URLLoader) != null){
		fashionDataXML = new XML(xmlLoader.data);
		fashionDataXML.ignoreWhitespace = true;
		}//if
		createMenu();
	}//function xmlLoaded
	
function createMenu ():void {
	var i:uint = 0;
	var tArray:Array;
	var links:XMLList = fashionDataXML..links;
	var container:MovieClip=new MovieClip;
	addChild(container);
	for ( var q=0;q<links.length();q++ ) {
		i=i+30;
		var myTextField:TextField=new TextField();
		myTextField.text=links[q];
		myTextField.x=30;
		myTextField.y=i;
		myTextField.width=300;
		myTextField.selectable=false;
		addChild(myTextField);
	}
}

Please paste the code into a action frame and test the movie. It will display all text read from your xml in a seperate textboxes.

Hope this helps!!!

thanks rajarajan07, i see that adds text boxes to the stage and my goal was to repalce existing text boxes, but very helpful to see other methods as well.

i eventually got it working to a point where i can move on for now by simply using the

if (q ==1){
}

then adding the first link with its index value into the text box on the stage. i wanted to loop the links01 and link02 in the dot syntax as well, but ill work on that another time : ).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.