473,326 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Interpreting String as function name actionscript 3.0

Hi
I want to know if there is any way a string can be interpreted as function name.I need this to call functions dynamically.Below is a code snippet which works fine if the function is in the same class as the function call.But what if i want to call a function present in another class or a different library.Any suggestions will be appreciated.

Expand|Select|Wrap|Line Numbers
  1. public var actionRef:String = "getit"
  2.  
  3. public function initApp():void
  4. {
  5. button.label="Click"
  6. canvas.addChild(button);
  7. button.addEventListener(MouseEvent.CLICK,callMe);
  8. }
  9.  
  10. public function callMe(event:MouseEvent):void
  11. {
  12. //if (this.hasOwnProperty(actionRef))
  13. this[actionRef]();
  14.  
  15. }
  16. public function getit():void
  17. {
  18. trace("inside getit")
  19. }
Cheers
mfsiddiq
Nov 21 '07 #1
2 12046
Here is the code. I use this strategy for dynamic assignment of functions to events, like nav items. Enjoy.

Expand|Select|Wrap|Line Numbers
  1. //  inside class containing function targeted by your string...
  2.  
  3. public function executeThis(myFunctionStringName:String, someID:uint):void {
  4.      var thisSoonToBeFunction:String = myFunctionStringName;
  5.      this[thisSoonToBeFunction](someID);
  6. }
  7.  
  8. public function nameOfMyFunction(someID:uint):void {
  9.    trace(someID);
  10. }
  11.  
  12. public function triggerIt() {
  13.     executeThis("nameOfMyFunction", 2);
  14. }
Feb 26 '08 #2
yozef
1
So I have something like this:

Expand|Select|Wrap|Line Numbers
  1. for (var i:int=0; i<menu_array.length(); i++) {
  2.         var _callBackFuntion:String = "openMenu" + i;
  3.         menu_array[i].addEventListener(MouseEvent.CLICK, _callBackFuntion);
  4.     }
Your system of using:

Expand|Select|Wrap|Line Numbers
  1. menu_array[i].addEventListener(MouseEvent.CLICK, this[_callBackFuntion]);
does Not Work, it gives me a type error: Error #1006: value is not a function.

Anybody got other ideas?
Oct 16 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Matt | last post by:
Hello, I am attempting to get a software prototype UI/demo built in Flash to talk with existing C++ (so I can exchange data and commands between the application-software already developed in the...
2
by: psundara | last post by:
Hi, I'm facing a peculiar problem of finding a way to interpret header information in a smart way. I have this header file that is shared by many users, which contains, among things, a few...
3
by: Chris Saunders | last post by:
I am attempting to write and interface from another language to some C code. I am having some difficulty interpreting a declaration. int (*SSL_CTX_get_verify_callback(SSL_CTX...
2
by: Fred Nelson | last post by:
I'm new to VB.NET and I have a situation in which I would like to interpret a varialble - this may have another name in vb so I will explain what I mean. In FoxPro you can "interpret" a variable...
4
by: jemptymethod | last post by:
http://htmatters.net/htm/1/2006/01/EIBTI-for-Javascript-explicit-is-better-than-implicit.cfm
7
by: Greg Buchholz | last post by:
I'm wondering if anyone has advice for figuring out error messages produced by g++. The programs below works fine, until I uncomment out the two "transform" lines. Then it points me to line 24...
3
by: JuneNasch | last post by:
Hi. I'm a beginner in using Actionscript. Do you know what is the actionscript for a button to exit or quit my project? I'm using Flash 8 pro. I don't know which version of actionscript is used,...
1
Unicron
by: Unicron | last post by:
Hey folks. I have searched high and low for the answer to what seems to be a simple problem. Perhaps I don't know how to describe the title properly so if this has been dealt with before, please...
9
by: WebArchitect | last post by:
I have a text file. My text file contains lines with double quotes around it. I trying to code if a line has double quotes around it Then make it bold My code is below and it is not working....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.