# Help: access a function from loaded swf

**URL:** <https://forum.kirupa.com/t/help-access-a-function-from-loaded-swf/261900>\
**Category:** Uncategorized\
**Created:** [June 1, 2008, 3:10pm UTC](https://forum.kirupa.com/t/help-access-a-function-from-loaded-swf/261900 "2008-06-01T15:10:49Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pier25](https://avatars.discourse-cdn.com/v4/letter/p/4af34b/32.png) [@Pier25](https://forum.kirupa.com/u/Pier25)\
**Post date:** [June 1, 2008, 3:10pm UTC](https://forum.kirupa.com/t/help-access-a-function-from-loaded-swf/261900/1 "2008-06-01T15:10:49Z")

</div>

I know this must be really simple, but I’m stuck in that and I need to finish 10 other thousand things for today…

I’m trying to access a function that’s on the document class, from a loaded swf.

I load an external banner, and when the banner has finished playing I want to call a function.

I’m trying:

myfunction();  
this.stage.myfunction();  
this.parent.myfunction();

with no luck…

Thanks 😉

---

<div class="post-metadata">

**Author:** ![flassari](https://avatars.discourse-cdn.com/v4/letter/f/6de8d8/32.png) [@flassari](https://forum.kirupa.com/u/flassari)\
**Post date:** [June 1, 2008, 6:16pm UTC](https://forum.kirupa.com/t/help-access-a-function-from-loaded-swf/261900/2 "2008-06-01T18:16:16Z")

</div>

I think what you are trying to do can be accomplished another way with event listeners.

On the last frame in the banner:  
[AS]dispatchEvent(new Event(“imDone”));[/AS]  
In the container swf:  
[AS]\_banner.addEventListener(“imDone”, onBannerDonePlaying);  
private function onBannerDonePlaying(e:Event):void {  
// remove the banner and continue.  
}[/AS]

---

<div class="post-metadata">

**Author:** ![Pier25](https://avatars.discourse-cdn.com/v4/letter/p/4af34b/32.png) [@Pier25](https://forum.kirupa.com/u/Pier25)\
**Post date:** [June 1, 2008, 8:06pm UTC](https://forum.kirupa.com/t/help-access-a-function-from-loaded-swf/261900/3 "2008-06-01T20:06:32Z")

</div>

I already solved it by using exactly the same approach you suggest.

Thanks anyway 😉

---

<div class="post-metadata">

**Author:** ![Alex\_Lexcuk](https://avatars.discourse-cdn.com/v4/letter/a/919ad9/32.png) [@Alex\_Lexcuk](https://forum.kirupa.com/u/Alex_Lexcuk)\
**Post date:** [June 1, 2008, 8:39pm UTC](https://forum.kirupa.com/t/help-access-a-function-from-loaded-swf/261900/4 "2008-06-01T20:39:01Z")

</div>

[http://www.flasher.ru/forum/showthread.php?t=112502](http://www.flasher.ru/forum/showthread.php?t=112502)

---

<div class="post-metadata">

**Author:** ![johnlouis](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/johnlouis/32/568_2.png) [@johnlouis](https://forum.kirupa.com/u/johnlouis)\
**Post date:** [June 3, 2008, 12:56am UTC](https://forum.kirupa.com/t/help-access-a-function-from-loaded-swf/261900/5 "2008-06-03T00:56:29Z")

</div>

i’m not having any luck with this method…  
i am trying to call a function during a MouseClick event.  
inside seperate button class:

```auto

public function takeSnapshot():void{
    dispatchEvent(new Event("snapshotTaken"));
}

```

inside my Main class/swf:

```auto

object.addEventListener("snapshotTaken", execute);
private function execute(e:Event):void{
    e.target.functionOfObject();
}
button.addEventListener(MouseEvent.CLICK, clicker);
private function clicker(e:MouseEvent):void{
    e.target.takeSnapshot();
}

```

---

<div class="post-metadata">

**Author:** ![flassari](https://avatars.discourse-cdn.com/v4/letter/f/6de8d8/32.png) [@flassari](https://forum.kirupa.com/u/flassari)\
**Post date:** [June 3, 2008, 11:37pm UTC](https://forum.kirupa.com/t/help-access-a-function-from-loaded-swf/261900/6 "2008-06-03T23:37:12Z")

</div>

What if you try e.currentTarget?

---

<div class="post-metadata">

**Author:** ![Felixz](https://avatars.discourse-cdn.com/v4/letter/f/ecb155/32.png) [@Felixz](https://forum.kirupa.com/u/Felixz)\
**Post date:** [June 4, 2008, 12:01am UTC](https://forum.kirupa.com/t/help-access-a-function-from-loaded-swf/261900/7 "2008-06-04T00:01:48Z")

</div>

the difference is only in bubbling phase.  
currentTarget is always am object which has the listener,  
target is an object dispatching an event
