PDA

View Full Version : Target path in nested movieclips


mxyntl
05-04-2007, 06:23 AM
I sure could use some help with accessing a function in a nested
movieclip. I can't figure out what the target path needs to be to
call the function "collapseTree" (in the my_tree movieclip) from
the main stage in loader.fla.

This is a large file so here's a schematic of the code and
structure of loader.fla:

in loader.fla

this.createClassObject(mx.controls.Loader, "treeldr", 11);
treeldr.contentPath = "treemain";
treeldr.scaleContent = true;
treeldr.setSize(230, 140);
treeldr.move(435, 115);

/************************************************** */

treemain movieclip

tree_sp_mc on stage (scrollpane movieclip)


/************************************************** */

tree_sp_mc (scrollpane movieclip)

this.createClassObject(ScrollPane, "tree_sp", 20);
tree_sp.contentPath ="my_tree";
tree_sp.setSize(460, 285);

/************************************************** */

my_tree movieclip

// code to parse and load text into tree here

// this resets tree to original size
function collapseTree():Void {
text_tree.setSize(tree_width, tree_height);
}

/************************************************** */

I tried to create an instance of the "treemain" and "my_tree"
movieclips in AS but I couldn't figure out where the instances
would go since each one is loaded into the contentPath of the
loader and the scrollpane respectively.

I also tried making "collapseTree" a global variable on the main stage
to which I assigned the "collapseTree" function in "my_tree", but,
that didn't work either.

I've been wrestling with this for several days and I'm burned out
on it. Any help would be greatly appreciated.

astgtciv
05-04-2007, 12:19 PM
I think something like


_root.treeldr.content.tree_sp_mc.tree_sp.content.c ollapseTree


should target it. The content mcs under the loader and scrollpane are accessed via the "content" field. Don't forget though that you might not be able to refer inside the content field right away after it's created, you have to wait - e.g., in case of the ScrollPane you have to wait for the ScrollPane to broadcast ScrollPane.complete event (signifying that the content has loaded).

SmackMe
05-04-2007, 03:31 PM
Also keep in mind that if that function is a function declared on the timeline, you can't access it from any other location but the same frame and just from inside of the movieclip.
To be able to access that function you should either make a custom class that extends MovieClip, or, if you don't want to mess with external actionscript classes, you could extend the MovieClip class itself like so:

// in movie1
MovieClip.prototype.yourFunction = function() {
trace("ahaaaaaaaaaa!");
}

// in movie2 that contains movie1
movie1.yourFunction();
// traces ahaaaaaaaaa!

mxyntl
05-04-2007, 07:39 PM
Hey thanks to both of you. Great ideas. I'll give 'em a try and post my results.