# External class problems with event function

**URL:** https://forum.kirupa.com/t/external-class-problems-with-event-function/269640
**Category:** Uncategorized
**Created:** [August 29, 2008, 11:53pm UTC](https://forum.kirupa.com/t/external-class-problems-with-event-function/269640 "2008-08-29T23:53:03Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Didi32](https://avatars.discourse-cdn.com/v4/letter/d/eb8c5e/32.png) [@Didi32](https://forum.kirupa.com/u/Didi32)
#### Post date: [August 29, 2008, 11:53pm UTC](https://forum.kirupa.com/t/external-class-problems-with-event-function/269640/1 "2008-08-29T23:53:03Z")

</div>

Hi:  
First of all, I would like to let you know that I am totally new to creating packages and classes externally from the main document.

I am currently trying to create a class that connects to a php file, gets some information and returns it into a String in the main timeline. I believe my problem is related to the fact event functions cannot return any value; but then, how can I get my string?

Here is the class:

```auto

package {
  import flash.display.*;
  import flash.events.*;
  import flash.net.*;

  public class CommentMaker extends Sprite {
  
  private var myLoader2:URLLoader = new URLLoader()

    public function CommentDisplayer(idNum) {

    myLoader2.dataFormat = URLLoaderDataFormat.VARIABLES
   
    myLoader2.load(new URLRequest('flashFile.php?id='+idNum))

    myLoader2.addEventListener(Event.COMPLETE, onDataLoad)
 
   function onDataLoad(evt:Event):String{
    var commentString:String = "";
        for(var i:uint=0; i<evt.target.data.cant; i++){
            var commentString = evt.target.data['Title'+i];

                              }
            return commentString;
                                     
                           }
                        
        }
        
  }

```

And here, in my main document:

```auto

var theComments:CommentMaker = new CommentMaker();
trace(theComments.CommentDisplayer(5));

```

What I want to get back is the commentString value I tried to returned. I think the problem is that I’m trying to return a value from an event function. I tried to return whatever variable from the main function CommentDisplayer and I got it back properly, but how - from loading the CommentDisplayer function, can I get the value of the string that is inside the event function (OnComplete).

Also, if you know where I can find good information on how to create good classes, I would be grateful.

Thanks a lot.  
Didi
