__call function in AS3 ?

Hello,

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

TIA

Eelco Luurtsema
eelcolAsked:
Who is Participating?
 
IqAndreasConnect With a Mentor Commented:
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.
0
 
CyanBlueCommented:
No, that's not possible in ActionScript...

CyanBlue
0
 
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 ?
0
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
CyanBlueCommented:
You can catch the error by wrapping it in try ... catch block, but you cannot call the function that generated the error...

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

http://www.kirupa.com/forum/showthread.php?t=336549
http://www.kirupa.com/forum/showthread.php?t=334671

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,
Andreas
0
 
IqAndreasCommented:
Otherwise, if you can check if a function exists by doing this:

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

OR

if (myClass["myFunction"] is Function)   { myClass.myFunction(); }
0
 
CyanBlueCommented:
__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...

CyanBlue
0
 
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.
0
 
alien109Commented:
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?
0
 
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 ?
0
 
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.
0
 
IqAndreasCommented:
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.

Cheers,
Andreas
0
 
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 !
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.