# Passing variables to and from externally loaded SWF?

**URL:** <https://forum.kirupa.com/t/passing-variables-to-and-from-externally-loaded-swf/323723>\
**Category:** flash\
**Created:** [July 13, 2011, 10:36pm UTC](https://forum.kirupa.com/t/passing-variables-to-and-from-externally-loaded-swf/323723 "2011-07-13T22:36:31Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![lazerbrains](https://avatars.discourse-cdn.com/v4/letter/l/b19c9b/32.png) [@lazerbrains](https://forum.kirupa.com/u/lazerbrains)\
**Post date:** [July 13, 2011, 10:36pm UTC](https://forum.kirupa.com/t/passing-variables-to-and-from-externally-loaded-swf/323723/1 "2011-07-13T22:36:31Z")

</div>

I have an SWF, called main.swf. Inside of that is a movieClip that Declares a variable “myVar”.

Then there is an external SWF that is loaded by main.swf. I am trying to get this external SWF to check the value of “myVar” and depending on what the value is, send the playhead in the main.swf to a certain frame.

I have it almost working, but it is giving me problems. And I am not sure it is the best way to do it.  
_**1)**_  
On the timeline of main.swf is a movieClip called “BG”. It has 6 frames. the first frame declares that variable, and each of the other 5 frames, set the value of it.  
_**2)**_  
I need the external swf to check the value of “myVar” to detemine where to send the playhead of the mian.swf. So on a frame in the external SWF, I have this code:  
Code:  
MovieClip(parent).addEventListener(Event.ENTER\_FRAME, fl\_EnterFrameHandler); function fl\_EnterFrameHandler(event:Event):void { dispatchEvent(new Event(“myVar\_value”, true)); }  
_**3)**_

Then on the main.swf timeline, I have this code to capture the dispatch and trigger the function:  
Code:  
addEventListener(“myVar\_value”, habitatBG) function habitatBG(event:Event):void{ if (myVar == “seashore”) { gotoAndStop(“seashore\_critters”); } }  
However this doesn’t work and it says:

```
Code:
1120: Access of undefined property myVar. 

```

I basically need to check a variable and send the main.swf to a certain frame. Does anyone know how I can do this?   
 ![](http://forum.kirupa.com/uploads/kirupa/3755/3aec295217693272.gif)[![](http://forum.kirupa.com/uploads/kirupa/3756/20ace7f93c5339be.gif)](http://www.actionscript.org/forums/newreply.php3?do=newreply&p=1087640)
