PDA

View Full Version : Classes - Returning value from other function



energy
September 3rd, 2009, 07:27 PM
Hey Guys,

I have a question regarding classes. Small example below.


Lets say my class is like this.

class MyClass
{

public function Clue // this will be called externally
{
something.addEventListener(NetStatusEvent.NET_STAT US, returnResult);
}

function returnResult(e:NetStatusEvent)
{
return success; //Result is generated in this function When NetConnection reports Status
//this is the result i want to return whosoever calls that function
}
}



So lets say i create an instance of this class

var s = new MyClass;
var f = s.clue();

What i want is that clue() should return me the value of NetStatus which is generated in returnResult() when this function is invoked.

Now in this case var "f" will become undefined because Clue() is not returning anything, so how can i find a way that value of NetStatusEvent.NET_STATUS (in this case) will be returned from Clue().

Although i can use ENTER FRAME EVENT to check when it has generated a status but i'm sure that there must be a better way.

Thanks in advance!

energy
September 3rd, 2009, 08:18 PM
Ok Solved!, The solution is defining your own events.

I will be interested in discussing more straightforward solutions though, if any.