Trying to pass movieclip name to function

Posted on 2008-11-12
Last Modified: 2013-11-11
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";


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"] =;

		tempMovie = this["menuName"];

		// assign node data

		this["menuHeader"] = mySubNode.childNodes[0].firstChild.nodeValue;

		tempText = this["menuHeader"];

		_level0.flyouts.tempMovie.menuHeader = tempText;


//**** SAMPLE XML FILE ****//



	<menuitem id="mySectionName">






Open in new window

Question by:cacklebunny
    LVL 39

    Expert Comment

    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.
    LVL 2

    Author Comment

    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.
    LVL 14

    Accepted Solution

    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


    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Suggested Solutions

    Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
    While working over numerous projects I often had the requirement for doing a screen capture in AS3.0. Unfortunately I found no "ready made" solutions in google search that suited my requirements. But I did come across some great resources which help…
    The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.
    The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now