# How to retain variables from onLoad event?

**URL:** <https://forum.kirupa.com/t/how-to-retain-variables-from-onload-event/65433>\
**Category:** flash\
**Created:** [September 26, 2004, 10:37am UTC](https://forum.kirupa.com/t/how-to-retain-variables-from-onload-event/65433 "2004-09-26T10:37:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Carlos](https://avatars.discourse-cdn.com/v4/letter/c/ecae2f/32.png) [@Carlos](https://forum.kirupa.com/u/Carlos)\
**Post date:** [September 26, 2004, 10:37am UTC](https://forum.kirupa.com/t/how-to-retain-variables-from-onload-event/65433/1 "2004-09-26T10:37:40Z")

</div>

G’day,

Is it possible to retain variable information after exiting an onLoad event?

I have a variable declared outside the onLoad event which a function called from within the onLoad event populates. The problem is, after leaving the onLoad event the variable gets cleared. Any solutions?

Cheers,  
c

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 26, 2004, 11:43am UTC](https://forum.kirupa.com/t/how-to-retain-variables-from-onload-event/65433/2 "2004-09-26T11:43:57Z")

</div>

what kind of variable? Loaded variables? They still exist after the onLoad event defined within the loadVars or XML object. Local variables, however will not (variables defined with var within the onLoad function block). For those, you can instead declare them outside the function in the scope of the script. That way they’ll be accessible from anywhere within the script. i.e.

```auto
var myvar;
my_lv.onLoad = function(){
    myvar = this.loadedvar;
}

```
