# Access variable in MainTimeLine

**URL:** <https://forum.kirupa.com/t/access-variable-in-maintimeline/633119>\
**Category:** flash\
**Created:** [May 3, 2015, 12:43pm UTC](https://forum.kirupa.com/t/access-variable-in-maintimeline/633119 "2015-05-03T12:43:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![panoss](https://avatars.discourse-cdn.com/v4/letter/p/db5fbb/32.png) [@panoss](https://forum.kirupa.com/u/panoss)\
**Post date:** [May 3, 2015, 12:43pm UTC](https://forum.kirupa.com/t/access-variable-in-maintimeline/633119/1 "2015-05-03T12:43:42Z")

</div>

I have preloader tha loads another swf, lets say game.swf.  
How can I access preloader’s variable from game.swf?

---

<div class="post-metadata">

**Author:** ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)\
**Post date:** [May 3, 2015, 1:00pm UTC](https://forum.kirupa.com/t/access-variable-in-maintimeline/633119/2 "2015-05-03T13:00:12Z")

</div>

The first question you should be asking is, does my game need to care about how its loaded? Why does it need to access the preloader (if there is one?) at all? The more self contained your swf is, the better.

Anywho, you can go through the `loaderInfo` property and access `loader` there. That should get you the Loader that’s loading the swf (the one in the preloader) which can in turn get you anywhere in your preloader DOM as that loader would likely be a child of that swf’s display list.

---

<div class="post-metadata">

**Author:** ![krilnon](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/krilnon/32/34_2.png) [@krilnon](https://forum.kirupa.com/u/krilnon)\
**Post date:** [May 4, 2015, 1:12am UTC](https://forum.kirupa.com/t/access-variable-in-maintimeline/633119/3 "2015-05-04T01:12:00Z")

</div>

Seems like ye olde `root` would likely work in this non-ideal scenario too. panoss is probably just grabbing some parameters from the preloader for some reason, and maybe game.swf can assume `root` is available.

All the suggestions you gave seem good to me…

---

<div class="post-metadata">

**Author:** ![panoss](https://avatars.discourse-cdn.com/v4/letter/p/db5fbb/32.png) [@panoss](https://forum.kirupa.com/u/panoss)\
**Post date:** [May 4, 2015, 8:55am UTC](https://forum.kirupa.com/t/access-variable-in-maintimeline/633119/4 "2015-05-04T08:55:27Z")

</div>

I 'm trying to make it work with MovieClip(root):

> //this code in the game  
> var m:MovieClip = MovieClip(root);  
> trace (“m.appRoot=” + m.appRoot);

But it gives error: m.appRoot=undefined…

I 'm loading the game with the loader of as3: (maybe this matters, that’s why I mention it)

> // this code is in the preloader  
> var appRoot=“localhost”;  
> // load game  
> var request:URLRequest = new URLRequest(“game.swf”);  
> var \_loader:Loader = new Loader();  
> \_loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgress);  
> \_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaded);  
> \_loader.load(request);

Also “trace(root as MovieClip).appRoot);” gives me the same error.
