__call function in AS3 ?


Is there a __call function in AS3, like in PHP ? I have a class which calls functions dynamicly and I want to catch these function calls in a __call function but I can't find anything about this. Is this possible


Eelco Luurtsema
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

No, that's not possible in ActionScript...

eelcolAuthor Commented:
I get the following error:

ReferenceError: Error #1069

Isn't it possible to catch this error, and then to call the function that generates the error (the one which doesn't exists) on another class ?
You can catch the error by wrapping it in try ... catch block, but you cannot call the function that generated the error...

Price Your IT Services for Profit

Managed service contracts are great - when they're making you money. Yes, you’re getting paid monthly, but is it actually profitable? Learn to calculate your hourly overhead burden so you can master your IT services pricing strategy.

Actually, (if I understand "__call" correctly) it is possible if that class extends the ActionScript Proxy class.


Whenever a property or function is being called or accessed, the "getProperty", "setProperty", and "callProperty" functions are run, and you can capture this.

Do you understand what it does? And I may have mistaken what __call does. I read the PHP reference on it, but I may have misunderstood, and if so, could you elaborate more on what the function does in PHP?

Good luck with your programming,
Otherwise, if you can check if a function exists by doing this:

if (myClass["myFunction"])
   {  myClass.myFunction(); }


if (myClass["myFunction"] is Function)   { myClass.myFunction(); }
__call() function in a nutshell is that you execute that function when your run a function that does not exist in a given class...  For example, Animal class has walk, talk and eat methods, but you were trying animalInstance.sleep() where the __call function will kick in since there is no sleep method defined in the Animal class...

The Proxy class is close, but I don't think it is quite the same thing...  You could extend the Proxy class and build your own, but I think that's quite extensive work you are looking...

Why not use Interface???  The Interface class basically is an agreement between the class provider and the developer where it tells you what you can and what you cannot...  As an author of a class that you are using, it does not make sense to cover the case when your user is calling something that you did not allowed them for...  That's my 2 cents...

eelcolAuthor Commented:
Well a NetConnection instance from my Flash Media Server calls a function in my class, but that function may not exists in that class. Thats what I need it for.

I am going to look at the callProperty.
can you use more of an event listener pattern, and rather than attempting to call the method on the object itself have that object listen for events broadcasted by the instance?
eelcolAuthor Commented:
I am looking at the option IqAndreas posted and it gets close.

The situation:
- From the Flash Media Server I call a function on the Actionscript on the user-side. I do this using the NetConnection Client.call() function. The documentation says that the function is :

clientObject.call(methodName, [resultObj, [p1, ... pN]])

- Strangely enough if I extend the Proxy class and have a callProperty, getProperty and setProperty function, the getProperty gets called when NetConnection calls a method ? In that way I lose the arguments.

So the problem seems to be that the Flash Media Server tries to retrieve an variabel (getProperty) while it should call a function ?
eelcolAuthor Commented:
So I am still searching for a solution for this.

I am trying to build an own NetConnection class and thats where I get this problems. It is comparable with writing an own database class in PHP.
Hey, sorry for the lack of response. I have been out and about traveling.

Do you think you could post the code you tried using with the Proxy class? I have an idea on how you can still keep the parameters even it runs the function "getProperty" instead, but it all depends on how your code is set up right now.

Other than the lack of parameter passing, does the code work as planned?

Sadly, I am unable to open FLA files in Linux, so plain text files with the code (or flex projects) would be best.

eelcolAuthor Commented:
Hi Andreas

I have managed to make a work-around for this with a kind of "catch-all" function.

All requests from Flash media server with NetConnection to a function, are being send to this function. This function then "redirects" the request to the right function in the parent class.

Is this a good solution or do you think you have a better one ?

Thanks !
Could you elaborate more on what you did, perhaps including some sample code. I don't quite understand what you mean from your description.

I'm quite curious how you got it solved, and might have some use for the solution in the future.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Development

From novice to tech pro — start learning today.