Trying to pass movieclip name to function

I can't seem to get my script to recognize a value of a movieclip I"m passing to a function.

I'm using Actionscript 2.0.

See code snippet for the function.


This doesn't work.  However, if I hardcode the actual values and just do:

_level1.flyouts.TheNameOfMyMovieClip.TheNameOfMyTextField = "foobar";

then the textfield will correctly read, "foobar."

Can you tell me what I'm doing wrong?
import com.xfactorstudio.xml.xpath.*;
var my_xml = new XML();
my_xml.scope = this;
my_xml.ignoreWhite = true;
       
XMLPathFile = "text.xml";
 
parseData("mySectionName");
 
function parseData(thesection) {
	
	var myXMLNode = XPath.selectNodes(my_xml, "//menuitem[@id='" + thesection + "']");
 
	//get text from XML file, line by line
	for (var i = 0; i<myXMLNode.length; i++) {
		var tempMovie:MovieClip;
		var tempText:TextField;
 
	                     mySubNode = myXMLNode[i];		
                                          this["menuName"] = mySubNode.attributes.id;
		tempMovie = this["menuName"];
 
		// assign node data
		this["menuHeader"] = mySubNode.childNodes[0].firstChild.nodeValue;
		tempText = this["menuHeader"];
 
		_level0.flyouts.tempMovie.menuHeader = tempText;
}
 
//**** SAMPLE XML FILE ****//
<xml>
  <root>
	<menuitem id="mySectionName">
		<menuHeader>Testing</menuHeader>
	</menuitem>
	
   </root>
</xml>

Open in new window

LVL 2
cacklebunnyAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
DesignbyonyxConnect With a Mentor Commented:
You are almost there... I can't really test at the moment, but you should be storing your temp variables as Strings and using the following syntax:

Please note, that if you trace a movieclip, you should get a full path :

trace(this); // Called from within movie2

Output: _level0.movie1.movie2

The reason you do not get an error is because your XML data has not been datatyped... so when you assign a variable of type Movieclip to this untyped data, flash doesn't know that you have made an invalid assignment.
var tempMovie:String;
var tempText:String;
 
// Assuming your textfield variable name is menuHeader
_level0.flyouts[tempMovie].menuHeader = tempText;
 
// The above could also be written:
_level0["flyouts"][tempMovie]["menuHeader"] = tempText;
 
// Notice how tempMovie has no quotes around it as we want to insert
// the String value of tempMovie.

Open in new window

0
 
blue-genieCommented:
hi, i'm not familiar with XPath that you're using, but i don't think thats your problem.
var myXMLNode  traces undefined.
so you need to fix that first.
0
 
cacklebunnyAuthor Commented:
myXMLNode traces fine for me.  In fact, if I trace tempMovie, it returns what I'd want, but I'm not sure if it's tracing the value as a string or a movieclip.

I think the crux of my problem is that I'm trying to pass a string name to the function and I want it to reference a movieclip of the same name.  For some reason it won't recognize it as a movieclip type event though I've declared it as such.
0
All Courses

From novice to tech pro — start learning today.