views:

215

answers:

3

I have an xml document that I would like to use to show MovieClips in my .fla:

<linkedMovieClip>TestClip</linkedMovieClip>

In my .fla, I created a symbol called TestClip and select Linkage > Export for Actionscript and named it TestClip.

My code in my Document class traces the xml:

var t:*= getDefinitionByName(String(slideItem.linkedMovieClip)) as Class;
var linked:MovieClip = new t();
trace("linked is..."+ linked); // outputs [Object TestClip];

However, when I compile, I am getting an Error #1065.

ReferenceError: Error #1065: Variable  is not defined.
    at global/flash.utils::getDefinitionByName()

I searched around and many sites recommended including the following imports:

import flash.utils.getDefinitionByName;
import TestClip;

And I included the following dummy variable:

public var _dummyClip:TestClip;

However, I am still getting an error message. When I check the debugger it's from this line:

var t:*= getDefinitionByName(String(slideItem.linkedMovieClip)) as Class;

Can anyone advise?

A: 

Where are you trying to do this? Is it inside of your .fla's document class (or on your .fla's timeline)? Is it inside of another class, external swf, or other? When you create your TestClip MovieClip, are you leaving it extending flash.display.MovieClip?

I was able to get it working without issue.

This is working for me:

package src 
{
    import flash.display.MovieClip;
    import flash.utils.getDefinitionByName;
    public class TestClass extends MovieClip
    {

        public function TestClass() 
        {
            var x:XML = <root><linkedMovieClip>TestClip</linkedMovieClip></root>;
            trace(x.linkedMovieClip.toString());
            var c:* = getDefinitionByName(String(x.linkedMovieClip));
            var mc:MovieClip = new c();
            addChild(mc);
        }

    }

}
sberry2A
It's in my document class, and the linked MovieClip is in my .fla.I have my document class in a folder called .src, does this make a difference?[Main.fla, myXMLFile.xml [src folder: Main.as]]
redconservatory
Also...the var t:* code is inside a loop inside of a function - to explain why there's no private/public declaration.
redconservatory
+1  A: 

Your code looks okay. Try creating an instance of TestClip in your program to make sure that it is compiled into the SWF. Trace out the fully qualified name and make sure it is indeed TestClip

var _dummyClip:TestClip = new TestClip();
trace(flash.getQualifiedClassName(_dummyClip));//what does it trace?
Amarghosh
+1  A: 

With the answer above, I see my problem now.

My XML looked like:

<items>
<item><linkedMovieClip>TestClip</linkedMovieClip></item>
<item><linkedMovieClip>TestClip</linkedMovieClip></item>
<item><linkedMovieClip>TestClip</linkedMovieClip></item>
<item></item>
<item><linkedMovieClip>TestClip</linkedMovieClip></item>
<item></item>
</items>

i.e. some items had nodes, some did not.

When I use a for each (var item:XML in itemList) loop to iterate through my XML nodes () the nodes that do not contain the node fail and return the Reference Error (since there is no node called "linkedMovieClip".

If I use a if statement to check for the existence of the node, it works:

 if (xmlListname.linkedMovieClip != undefined) {

         trace(String(xmlListname.linkedMovieClip));
  var c:* = getDefinitionByName(String(xmlListname.linkedMovieClip)) as Class;
         var mc:MovieClip = new c();
  trace(mc);
 }
redconservatory