# Problem writing a function using LoadVars

**URL:** <https://forum.kirupa.com/t/problem-writing-a-function-using-loadvars/195121>\
**Category:** Uncategorized\
**Created:** [July 28, 2006, 3:13pm UTC](https://forum.kirupa.com/t/problem-writing-a-function-using-loadvars/195121 "2006-07-28T15:13:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![graylensman](https://avatars.discourse-cdn.com/v4/letter/g/5f9b8f/32.png) [@graylensman](https://forum.kirupa.com/u/graylensman)\
**Post date:** [July 28, 2006, 3:13pm UTC](https://forum.kirupa.com/t/problem-writing-a-function-using-loadvars/195121/1 "2006-07-28T15:13:38Z")

</div>

I’m loading external text files into a textbox when you click buttons, like so:

```auto
blueBtn.onRelease=function(){
    loadText=new LoadVars();
    loadText.load("blueText.txt");
    loadText.onLoad=function(success){
        if(success){
            newsBox.html=true;
            newsBox.htmlText=this.myNews;
        }
    }
}

```

This works fine, no problem. But I’ve got a bunch of buttons. So, I write this as a function:

```auto
function grabText(file, fileVar) {
    loadText = new LoadVars();
    loadText.load(file);
    loadText.onLoad = function(success) {
        if (success) {
            trace("I have your data, Commander.")
            newsBox.html = true;
            newsBox.htmlText = file.fileVar;
        }
    };
}
blueBtn.onRelease = function() {
    grabText("blueText.txt", "myNews");
};

```

And then I have trouble. The trace works fine, but “undefined” appears in the textbox.

Any ideas what I’m doing wrong? I’m sure it’s something simple/stupid, but I can’t find it. 🙂 Thanks!
