Doug Wolfgram
Doug Wolfgram

Reputation: 2126

How can I call a function in a parent movieclip from an externally-loaded child?

I have a swf file that is my 'shell' program that contains many functions. This shell program loads child movies. In the root timeline of the child movie, I have the following code:

function putresponse(q,r) {
    trace (r);
    _root.debug(r);
}
_root.debug("foo");

Debug is a function that writes some text to the screen. When I run this locally, the putresponse function gets called and the trace happens. When I run it remotely (inside the shell) the first debug happens immediately on load (as you'd expect) but then later when putresponse is called, the debug(r) is not executed. The external clip is at the same url as the shell so I don't think it is a security issue. Also, as I said, the debug("foo") works fine. This one really has me perplexed. Can anyone shed some light as to why I can't call the debug from _root when called from a function rather than on the first-level timeline?

EDIT: The call to putresponse is coming form two layers deep in local (within the child MC) MCs. The actual call is:

_parent._parent.putrepsonse(q,r);

Upvotes: 0

Views: 275

Answers (1)

mga
mga

Reputation: 1970

Is this an externally-loaded SWF using the Loader class? Might want to try:

req = new URLRequest("test.swf"); // test.swf has function foo()
ldr = new Loader();
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, sayFoo);
ldr.load(req);
someclip.addChild(ldr);
function sayFoo(event:Event):void {
   externalSwf = event.target.content;
   externalSwf.foo();
}

Check: http://www.kirupa.com/forum/showthread.php?290484-How-to-execute-a-function-in-an-externally-loaded-swf

Upvotes: 1

Related Questions