Skip to main content
birddog02
Participant
August 20, 2014
Question

Trying to call a root level function from within a loaded swf

  • August 20, 2014
  • 3 replies
  • 1946 views

I'm not very familiar with AS3... I'm trying to have a loaded swf file call a function from the parent to unload itself when it comes to the end (on the timeline, not as a button). I'm assuming I need to be calling the function (that is used for the close button) from the loaded swf (perhaps I'm mistaken though?).

Here's the code from one of my buttons that loads an swf. I'm guessing I need to call the closeSWF function from the timeline of my loaded movie but having no luck figuring out how to do that.

Any help would be appreciated.

// 01 ------------------------------------------------------

function loadWeaving(ev:MouseEvent):void {

  // load SWF

  var movieClip:MovieClip = new holder_mc;

  //add it to the stage

  addChild(holderSWF);

  holderSWF.x=0;

  holderSWF.y=0;

  //

  var requestEN:URLRequest = new URLRequest("WhatIsWeaving_Eng.swf"); // english

  holderSWF.load(requestEN);

 

  //

  close_bt.addEventListener(MouseEvent.CLICK, closeSWF);

  function closeSWF(infoObject:Object):void {

  trace("close SWF");

  removeChild(holderSWF);

  // reset switch

  close_bt.visible = false;

  showAllButtons();

  infoObject.currentTarget.removeEventListener(infoObject.type, closeSWF);

  }

  //

  setChildIndex(close_bt,numChildren - 1);

  close_bt.visible = true;

  hideAllButtons();

  // - start timer last

  myTimer.addEventListener(TimerEvent.TIMER, closeSWF);

}

This topic has been closed for replies.

3 replies

birddog02
birddog02Author
Participant
August 21, 2014

I think maybe I'm going about this the wrong way... Should I be using some kind of event listener in the main swf which would trigger when the loaded swf file comes to a specific frame (that I designate as the end)? Still beyond my AS3 grasp, but seems like the way to tackle it so it's done from within my container swf instead of from the loaded swf...

kglad
Community Expert
Community Expert
August 21, 2014

you can but you'll still need to use the content property of your loader.

Participating Frequently
August 21, 2014

Seriously, I use this:  "(this.parent as MovieClip).functionName(); (or (this.parent.parent... as MovieClip).functionName();)  all the time to call a function from the timeline of an imported swf.

It works!  :-)

kglad
Community Expert
Community Expert
August 21, 2014

i assume holderSWF is a loader class object.  if so, its content (cast as a movieclip) will reference the loaded swf's main timeline.  if your function is on that loaded swf's main timeline, after loading is complete you can use:

MovieClip(holderSWF.content).yourloadedswfsfunction();

p.s. here's an adobe kb article i wrote on swf-to-swf communication,  http://kb2.adobe.com/community/publishing/918/cpsid_91887.html

Participating Frequently
August 21, 2014

Honestly, I didn't exactly follow all of that because I'm a bit pressed for time.  But if I had an SWF (which I was going to be importing at runtime) and Iw anted a function to be called from it's timeline, I would use something like (this.parent as MovieClip).functionName();

Participating Frequently
August 21, 2014

Ah okay.  It would be something like this:

(this.parent as MovieClip).closeSWF(myObject);


If the script were on a timeline within a MovieClip on the timeline of your imported SWF, it would be this:

(this.parent.parent as MovieClip).closeSWF(myObject);

and so on........................