Solved

__call function in AS3 ?

Posted on 2010-05-01
16
809 Views
Last Modified: 2013-11-19
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
0
Comment
Question by:eelcol
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 3
  • +1
16 Comments
 
LVL 37

Expert Comment

by:CyanBlue
ID: 32414325
No, that's not possible in ActionScript...

CyanBlue
0
 

Author Comment

by:eelcol
ID: 32415323
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
 
LVL 37

Expert Comment

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

CyanBlue
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Expert Comment

by:IqAndreas
ID: 32427959
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
 
LVL 8

Expert Comment

by:IqAndreas
ID: 32428134
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
 
LVL 37

Expert Comment

by:CyanBlue
ID: 32428785
__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
 

Author Comment

by:eelcol
ID: 32429432
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
 
LVL 12

Expert Comment

by:alien109
ID: 32439067
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
 

Author Comment

by:eelcol
ID: 32447352
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
 

Author Comment

by:eelcol
ID: 32670217
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
 
LVL 8

Expert Comment

by:IqAndreas
ID: 32707143
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
 

Author Comment

by:eelcol
ID: 32772432
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
 
LVL 8

Accepted Solution

by:
IqAndreas earned 500 total points
ID: 32773203
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question